如何在azure上的同一个云服务中部署多台计算机

时间:2014-02-12 14:44:36

标签: python linux azure azure-cloud-services

我正在尝试使用Python API在Windows Azure上部署多个Linux虚拟机,但是部署它们时出错。当我为单个虚拟机创建单个云服务但不能为多个节点工作时,以下代码:

def createMachine(self,vmname,num,sms,region,affGrp,medialink,imageID,cert_data,cert_format,cert_password,linux_config,os_hd,endpoint_config,instanceSize,Service_name):
            exitF = 0
            if exitF:
                    thread.exit()
            else:
                    endpoint3 = ConfigurationSetInputEndpoint(name='SSH'+str(num), protocol='tcp', port='220'+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)
                    vname                   = vmname+str(num+1)
                    #Service_url    = self.newCloudService(sms,vname,name,name,region,affGrp)
                    #Service_name   = vname
                    media_link              = medialink+name+".vhd"
                    self.logger.info("Configuring Media Link "+media_link+".......... Ok")
                    # Configuring Image ID:
                    #----------------------
                    os_hd      = OSVirtualHardDisk(imageID, media_link)
                    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)
                    print "*"*40+":"+Service_name
                    result = sms.create_virtual_machine_deployment(service_name=Service_name,
                            deployment_name=vname,
                            deployment_slot='production',
                            label=vname,
                            role_name=vname,
                            system_config=linux_config,
                            os_virtual_hard_disk=os_hd,
                            network_config=endpoint_config,
                            role_size=instanceSize)
                    operation_result = sms.get_operation_status(result.request_id)
                    self.logger.info("Start Deployment.......... Ok")
                    self.logger.info("ssh  -i keys/mycert.pem "+"ehpcuser@"+Service_name+".cloudapp.net")
                    #self.instances.append(Service_name+".cloudapp.net")
                    exitF = 1
                    return (Service_name+".cloudapp.net")

,错误是:

 self.instance = self.azureclient.createMachine(self.vmname,self.num,self.sms,self.region,self.affGrp,self.medialink,self.imageID,self.cert_data,self.cert_format,self.cert_password,self.linux_config,self.os_hd,self.endpoint_config,self.instanceSize,self.Service_name)
File "/home/ehpcuser/ehpcazure/azurehpc.py", line 283, in createMachine
role_size=instanceSize)
 File "/home/ehpcuser/ehpcazure/azure/servicemanagement/servicemanagementservice.py", line 913, in create_virtual_machine_deployment
async=True)
File "/home/ehpcuser/ehpcazure/azure/servicemanagement/servicemanagementclient.py", line 119, in _perform_post
response = self._perform_request(request)
File "/home/ehpcuser/ehpcazure/azure/servicemanagement/servicemanagementclient.py", line 78, in _perform_request
return _management_error_handler(e)
File "/home/ehpcuser/ehpcazure/azure/servicemanagement/__init__.py", line 697, in _management_error_handler
return _general_error_handler(http_error)
File "/home/ehpcuser/ehpcazure/azure/__init__.py", line 644, in _general_error_handler
raise WindowsAzureConflictError(_ERROR_CONFLICT)

WindowsAzureConflictError

任何人都可以帮我解决这个问题

谢谢!!

2 个答案:

答案 0 :(得分:2)

使用add_role而不是create_virtual_machine_deployment()将新虚拟机添加到现有部署,其中服务名称是已创建的第一个虚拟机的托管服务名称和部署名称:

       .........
       ..........
       result = sms.add_role(service_name=Service_name,
                            deployment_name=Service_name,
                            role_name=vname,
                            system_config=linux_config,
                            os_virtual_hard_disk=os_hd,
                            network_config=endpoint_config,
                            role_size=instanceSize)

       .............

答案 1 :(得分:0)

我发现测试的代码添加了2个角色,第一个角色作为临时插槽部署角色,在部署暂存插槽角色后添加新角色作为生产部署角色,具有与暂存部署名称相同的名称(第1个角色) )。有关详细信息,请查看test_add_role_linux():https://github.com/WindowsAzure/azure-sdk-for-python/blob/master/tests/test_servicebusmanagementservice.py