How to connect a new VM to an existing VM with Powershell
I see that I can "connect to an existing virtual machine" in the portal, as opposed to creating a standalone virtual machine. How can I do that via powershell? I only see that the New-AzureVM command allows you to create a VM in a new cloud service, or in an existing cloud service. But I if I try to use that and point it to an existing cloud service that has a copy of my VM running already, it gives me an error, saying "The specified deployment slot Production is occupied".
Is there a different command that I'm missing?
Please let me know if this is what you are looking for.
How to create an IaaS VM on an existing cloud Service?
It can be done using PowerShell.
The command below creates a VM on an existing cloud service.
New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName Existingcloudservicename
If you need to add to a subnet:
The command below creates a VM on an existing cloud service and adds it to a specified subnet on the Vnet for that cloud service.
Note: subnet name is case sensitive.
New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | Set-AzureSubnet SUbnetNAme | New-AzureVM –ServiceName ExistignCloudServiceName
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
Rock,
The Virtual Machines service is our IaaS offering (AKA Persistent VMs. Using IaaS they VMs will always be single instance. To create multiple instance of a virtual machine you need to use Cloud Services to deploy VM Worker Roles and VM Web Roles (PaaS).
More information: http://msdn.microsoft.com/en-us/library/windowsazure/gg432976.aspx
This forum is to provide support for IaaS Virtual Machines only. This may be the forum you are looking for: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
Rock,
no doubt you are using a PaaS. I am moving your thread to the correct forum.
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
GRRRRRRRRRR, no I am not. Are you reading the post?
I create a virtual machine in Azure, based on the Windows 2012 OS. I installed and configured some software. I captured and persisted that image. Now if I create a virtual machine in the portal from my captured image, I have the option to create a standalone virtual machine, or a connected virtual machine. I can create a connected virtual machine which uses the same cloud service as my original virtual machine is running in. I just did it. All I want to know is if/how it can be done from Powershell.
Rock,
I apologize if I did not understood your question correctly. The command to deploy a new Azure VM on an existing cloud service is below. You can specify your custom image on the -ImageName paramenter. On the example we are using a standard image from the galley.
The command below creates a VM on an existing cloud service.
New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName Existingcloudservicename
If you need to add to a subnet:
The command below creates a VM on an existing cloud service and adds it to a specified subnet on the Vnet for that cloud service.
Note: subnet name is case sensitive.
New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | Set-AzureSubnet SUbnetNAme | New-AzureVM –ServiceName ExistignCloudServiceName
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
Let's try it this way. I can run your first command to get my VM started in an existing cloud service. Now once that is going, if you go to the portal, start a new VM, and go through the steps, you come to the step shown below. In this step, I can choose
to Connect to an existing VM. If I select this, I can then select the cloud service that has the VM running (that your command created). When I finish this in the portal, I get a new VM started from the same VM image. So now I have 2 VMs running in that cloud
service.
The problem is that if instead of using the portal, I use your command to try to create this second VM, the script gives an error saying that there is already something in the cloud service's Production slot. So I'm guessing the command is trying to use the Standalone option instead of the Connect option. So I want to know if I can run a PS command to create a VM that is connected to the first/existing VM in the cloud service.
Rock,
I think now I understand. The command I posted should create the VM on an existing Cloud Service, I have used it myself for that purpose a number of times. Since you are getting an error when running that command we need to investigate further.
Can you post the exact command line you are using here on the forum? You can change the cloud service name, etc,, to keep privacy.
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
This is the script that I basically found to use.
$subID = "<ID>"
$thumbprint = "<Thumb>"
$myCert = Get-Item cert:\\CurrentUser\My\$thumbprint
Set-AzureSubscription –SubscriptionName '<sub>' -SubscriptionId $subID -Certificate $myCert
Set-AzureSubscription -SubscriptionName 'Sub' -CurrentStorageAccount '<store>'
$imgName = “<myCustomImage>”
#Setup the VM DNS settings
$advmIP = “<AD IP>”
$advmName = “<AD computer>”
$dns1 = New-AzureDns -Name $advmName -IPAddress $advmIP
#Setup the VM config
$vmName = "comp1"
$adminPassword = “<pwd>”
$domainPassword = “<pwd>”
$domainUser = "<user>"
$FQDomainName = "domain.me.com"
$advm1 = New-AzureVMConfig -Name $vmName -InstanceSize Small -ImageName $imgName | Add-AzureProvisioningConfig -WindowsDomain -Password $adminPassword -Domain 'domain' -DomainPassword $domainPassword -DomainUserName $domainUser -JoinDomain $FQDomainName
#Create the VM
$serviceName = "<cloudService>"
$affinityGroup = "eusa"
$adVNET = "my-vm-net"
New-AzureVM -ServiceName $serviceName -VMs $advm1 -DnsSettings $dns1 -VNetName $adVNET
If I run this when I have no VMs yet, it works and creates the first VM in the cloud service. Now I want to basically run this again, just changing the $vmName to a new computer name. But since there is already a VM running in the cloud service, the PS commands give me an error telling me that there is something running in Production. So the commands are just trying to deploy a Standalone VM, but I need a command that will deploy a Connected VM now.
I believe the problem is that you cannot specify the -VNetMame when adding a new VM to an existing cloud service. All VMs in the cloud service share the same -VNetName.
If you could test running the command I posted "as is" only modifying the purple parts and not adding or removing anything else it should work.
You can then delete the test VM and on your script you most likely have to remove the -VNetName parameter when running it on a cloud service that already have a VM. Please note that if there is not VMs in the cloud service then -VNetName will be required.
New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName Existingcloudservicename
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
Have you tried re-creating the cloud service? There is a remote chance you are running on an issue with a Cloud Service that failed to deploy correctly.
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
I am also seeing this problem -- with the same script I can never add a VM to an existing service. Same error about a VM already occupying that slot.
Is there any resolution? This is very frustrating since it prevents me from automating my deployment.
Clamanna,
I just tested the following command once again, note this is the same command higher up on this thread.
New-AzureVMConfig -Name MyTestVM1 -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201210.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName MyServiceName
To see a list of available images you can issue a Get-AzureVMImage
Change the "MyServiceName" to the name of your cloud service.
Instead of running the script, could you try the command above? I expect it to work just fine.
Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support
|