示例#1
0
 def get_network_config(self, service, update):
     """
     Return None if image type is vm and not update
     Public endpoint should be assigned in real time
     :param service:
     :return:
     """
     if self.is_vm_image() and not update:
         return None
     cs = self.virtual_environment[AZURE_UNIT.T_CS]
     nc = self.virtual_environment[AZURE_UNIT.T_NC]
     network_config = ConfigurationSet()
     network_config.configuration_set_type = nc[AZURE_UNIT.T_NC_CST]
     input_endpoints = nc[AZURE_UNIT.T_NC_IE]
     # avoid duplicate endpoint under same cloud service
     assigned_endpoints = service.get_assigned_endpoints(
         cs[AZURE_UNIT.T_CS_SN])
     endpoints = map(lambda i: i[AZURE_UNIT.T_NC_IE_LP], input_endpoints)
     unassigned_endpoints = map(
         str, find_unassigned_endpoints(endpoints, assigned_endpoints))
     map(lambda (i, u): i.update({AZURE_UNIT.T_NC_IE_PO: u}),
         zip(input_endpoints, unassigned_endpoints))
     for input_endpoint in input_endpoints:
         network_config.input_endpoints.input_endpoints.append(
             ConfigurationSetInputEndpoint(
                 input_endpoint[AZURE_UNIT.T_NC_IE_N],
                 input_endpoint[AZURE_UNIT.T_NC_IE_PR],
                 input_endpoint[AZURE_UNIT.T_NC_IE_PO],
                 input_endpoint[AZURE_UNIT.T_NC_IE_LP]))
     return network_config
示例#2
0
 def get_network_config(self, service, update):
     """
     Return None if image type is vm and not update
     Public endpoint should be assigned in real time
     :param service:
     :return:
     """
     if self.is_vm_image() and not update:
         return None
     cs = self.virtual_environment[AZURE_UNIT.T_CS]
     nc = self.virtual_environment[AZURE_UNIT.T_NC]
     network_config = ConfigurationSet()
     network_config.configuration_set_type = nc[AZURE_UNIT.T_NC_CST]
     input_endpoints = nc[AZURE_UNIT.T_NC_IE]
     # avoid duplicate endpoint under same cloud service
     assigned_endpoints = service.get_assigned_endpoints(cs[AZURE_UNIT.T_CS_SN])
     endpoints = map(lambda i: i[AZURE_UNIT.T_NC_IE_LP], input_endpoints)
     unassigned_endpoints = map(str, find_unassigned_endpoints(endpoints, assigned_endpoints))
     map(lambda (i, u): i.update({AZURE_UNIT.T_NC_IE_PO: u}), zip(input_endpoints, unassigned_endpoints))
     for input_endpoint in input_endpoints:
         network_config.input_endpoints.input_endpoints.append(
             ConfigurationSetInputEndpoint(
                 input_endpoint[AZURE_UNIT.T_NC_IE_N],
                 input_endpoint[AZURE_UNIT.T_NC_IE_PR],
                 input_endpoint[AZURE_UNIT.T_NC_IE_PO],
                 input_endpoint[AZURE_UNIT.T_NC_IE_LP]
             )
         )
     return network_config
示例#3
0
 def assign_public_endpoints(self, cloud_service_name, deployment_slot, virtual_machine_name, private_endpoints):
     """
     Assign public endpoints of cloud service for private endpoints of virtual machine
     Return None if failed
     :param cloud_service_name:
     :param deployment_slot:
     :param virtual_machine_name:
     :param private_endpoints: a list of int or str
     :return: public_endpoints: a list of int
     """
     self.log.debug('private_endpoints: %s' % private_endpoints)
     assigned_endpoints = self.service.get_assigned_endpoints(cloud_service_name)
     self.log.debug('assigned_endpoints: %s' % assigned_endpoints)
     if assigned_endpoints is None:
         return self.ERROR_RESULT
     # duplicate detection for public endpoint
     public_endpoints = find_unassigned_endpoints(private_endpoints, assigned_endpoints)
     self.log.debug('public_endpoints: %s' % public_endpoints)
     deployment_name = self.service.get_deployment_name(cloud_service_name, deployment_slot)
     network_config = self.service.get_virtual_machine_network_config(cloud_service_name,
                                                                      deployment_name,
                                                                      virtual_machine_name)
     # compose new network config to update
     new_network_config = add_endpoint_to_network_config(network_config, public_endpoints, private_endpoints)
     if new_network_config is None:
         return self.ERROR_RESULT
     try:
         result = self.service.update_virtual_machine_network_config(cloud_service_name,
                                                                     deployment_name,
                                                                     virtual_machine_name,
                                                                     new_network_config)
     except Exception as e:
         self.log.error(e)
         return self.ERROR_RESULT
     if not self.service.wait_for_async(result.request_id, self.TICK, self.LOOP):
         self.log.error('wait for async fail')
         return self.ERROR_RESULT
     if not self.service.wait_for_virtual_machine(cloud_service_name,
                                                  deployment_name,
                                                  virtual_machine_name,
                                                  self.TICK,
                                                  self.LOOP,
                                                  AVMStatus.READY_ROLE):
         self.log.error('%s [%s] not ready' % (AZURE_RESOURCE_TYPE.VIRTUAL_MACHINE, virtual_machine_name))
         return self.ERROR_RESULT
     return public_endpoints