Quantcast
Channel: Azure Virtual Machines forum
Viewing all articles
Browse latest Browse all 12545

add multiple roles to same cloud service python api

$
0
0

How can i add a multiple roles to the same cloud service. i created two machines, the 1st is working correctly and the second role i created using the create_virtual_machine_deployment() but in the staging slot not a production slot then tried to add this deployment as an role to the same cloud service but add_role() method failed to add this machine to the cloud service !! the following is the python code of the 2nd machine that i need to add to the same cloud service:

	linux_config    = LinuxConfigurationSet(hostname+str(num+1)+"a", username, password , True)
                        publickey       = PublicKey(thumbprint, pkfile)
                        linux_config.ssh.public_keys.public_keys.append(publickey)
                        self.logger.info("Linux VM Configuration.......... Ok")
                        endpoint3 = ConfigurationSetInputEndpoint(name='SSH'+str(num), protocol='tcp', port='2220'+str(num), local_port='22', load_balanced_endpoint_set_name=None, enable_direct_server_return=False)
                        endpoint_config.input_endpoints.input_endpoints.append(endpoint3)
                        media_link              = ""
                        name                    = vmname+str(num+1)+"a"
                        vname                   = vmname+str(num+1)
                        media_link              = medialink+name+".vhd"
                        self.logger.info("Configuring Media Link "+media_link+".......... Ok")
                        # Configuring Image ID:
                        #----------------------
                        os_hd1     = OSVirtualHardDisk(imageID,media_link ,disk_label=name+".vhd")
                        self.logger.info("Configuring The Virtual Hard Disk using Image ID:"+imageID+".......... Ok")
                        self.logger.info("Deploying Node number:"+str(num)+".......... Ok")
                        result_cert = sms.add_service_certificate(service_name=Service_name,
                                                        data=cert_data,
                                                        certificate_format=cert_format,
                                                        password=cert_password)
                        self.logger.info("Start Deploying VM with Name: "+vname)
                        try:
                                self.logger.info(vars(result_cert))
                        except:
                                self.logger.info("Error: Can not configure the certifications")
                        time.sleep(5)
                        # Creating Staging node:
                        # Linux VM Configuration:
                        linux_config    = LinuxConfigurationSet(hostname+str(num+1), username, password , True)
                        publickey       = PublicKey(thumbprint, pkfile)
                        linux_config.ssh.public_keys.public_keys.append(publickey)
                        self.logger.info("Linux VM Configuration.......... Ok")
                        vname1 = vname+"a"
                        Deployment_name = Service_name+"a"
                        self.logger.info("deploying Staging slot. VM name: "+vname1+" Deployment name: "+Deployment_name)
                        result = sms.create_virtual_machine_deployment(service_name=Service_name,
                                        deployment_name=Deployment_name,
                                        deployment_slot='staging',
                                        label=Deployment_name+"label",
                                        role_name=vname1,
                                        system_config=linux_config,
                                        os_virtual_hard_disk=os_hd1,
                                        network_config=endpoint_config,
                                        role_size=instanceSize)
                        self.wait_for_async(sms, result.request_id)
                        print "*"*100
                        self.wait_for_deployment_status(sms,Service_name, Deployment_name, 'Running')
                        #self.wait_for_role_instance_status(sms,Service_name, Deployment_name, vname1, 'Running')
                        time.sleep(170)
                        # Creating Role in production slot
                        self.logger.info("Deploying the instance in production slot")
                        name = name[:-1]
                        media_link              = medialink+vname+".vhd"
                        self.logger.info("Media Link: "+media_link)
                        self.logger.info("Virtual Machine Name: "+vname)
                        self.logger.info("Deployment name: "+Deployment_name)
                        self.logger.info("Service name: "+Service_name)
                        # Linux VM Configuration:
                        linux_config    = LinuxConfigurationSet(hostname+str(num+1), username, password , True)
                        publickey       = PublicKey(thumbprint, pkfile)
                        linux_config.ssh.public_keys.public_keys.append(publickey)
                        self.logger.info("Linux VM Configuration.......... Ok")
                        os_hd   = OSVirtualHardDisk(imageID, media_link)              
                        result = sms.add_role(service_name=Service_name,
                                        deployment_name=Deployment_name,
                                        role_name=vname,
                                        system_config=linux_config,
                                        os_virtual_hard_disk=os_hd,
                                        network_config=endpoint_config,
                                        role_size=instanceSize)


 

the output of adding role:

{'status': u'Failed', 'error': <azure.servicemanagement.OperationError object at 0x22d7490>, 'id': u'', 'http_status_code': u'400'}


Ahmed Abdullah



Viewing all articles
Browse latest Browse all 12545

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>