Creating azure VM from image with Node SDK

2020-04-14 07:47发布

I'm trying to use the azure sdk (azure-sdk-for-node) to create a virtual machine based on an image i've already saved. I've also already created the service.

Here is what I've got:

// Create a virtual machine in the cloud service.
computeManagementClient.virtualMachines.createDeployment('prerender-pro', {
  name: "prerender-pro",
  deploymentSlot: "Production",
  label: "for heavy duty caching",
  roles: [{
    roleName: "prerender-pro",
    roleType: "PersistentVMRole",
    label: "for heavy duty caching",
    oSVirtualHardDisk: {
      sourceImageName: "prerender-os-2014-07-16",
      mediaLink: "https://XXXXXXX.blob.core.windows.net/vhds/prerender-os-2014-07-16.vhd"
    },
    dataVirtualHardDisks: [],
    configurationSets: [{
      configurationSetType: "LinuxProvisioningConfiguration",
      adminUserName: "Blah",
      adminPassword: "Blahblah2014!",
      computerName: 'prerender-pro',
      enableAutomaticUpdates: true,
      resetPasswordOnFirstLogon: false,
      storedCertificateSettings: [],
      inputEndpoints: []
    }, {
      configurationSetType: "NetworkConfiguration",
      subnetNames: [],
      storedCertificateSettings: [],
      inputEndpoints: [{
        localPort: 3389,
        protocol: "tcp",
        name: "RemoteDesktop"
      }]
    }]
  }]
}, function (err, result) {
  if (err) {
    console.error(err);
  } else {
    console.info(result);
  }
});

And the error I'm getting is this. I follow the example in the github readme almost exactly. Not sure why this is an issue.

{ [Error: A computer name must be specified.]
  code: 'BadRequest',
  statusCode: 400,
  requestId: '9206ea1e591eb4dd8ea21a9196da5d74' }

Thanks!

1条回答
时光不老,我们不散
2楼-- · 2020-04-14 08:34

It turns out that the error message is inaccurate. When deploying a Linux instance, only the "HostName" is required when defining the Configuration Set. "ComputerName" applies only to Windows instances. Here's an example of C# code:

ConfigurationSet configSet = new ConfigurationSet
        {
            HostName = "VMTest",
            UserName="xxxxx",
            UserPassword="xxxx",
            ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration
         }
查看更多
登录 后发表回答