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[self.T_CS] nc = self.virtual_environment[self.T_NC] network_config = ConfigurationSet() network_config.configuration_set_type = nc[self.T_NC_CST] input_endpoints = nc[self.T_NC_IE] # avoid duplicate endpoint under same cloud service assigned_endpoints = service.get_assigned_endpoints(cs[self.T_CS_SN]) endpoints = map(lambda i: i[self.T_NC_IE_LP], input_endpoints) unassigned_endpoints = map( str, find_unassigned_endpoints(endpoints, assigned_endpoints)) map(lambda (i, u): i.update({self.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[self.T_NC_IE_N], input_endpoint[self.T_NC_IE_PR], input_endpoint[self.T_NC_IE_PO], input_endpoint[self.T_NC_IE_LP])) return network_config
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[self.T_CS] nc = self.virtual_environment[self.T_NC] network_config = ConfigurationSet() network_config.configuration_set_type = nc[self.T_NC_CST] input_endpoints = nc[self.T_NC_IE] # avoid duplicate endpoint under same cloud service assigned_endpoints = service.get_assigned_endpoints(cs[self.T_CS_SN]) endpoints = map(lambda i: i[self.T_NC_IE_LP], input_endpoints) unassigned_endpoints = map(str, find_unassigned_endpoints(endpoints, assigned_endpoints)) map(lambda (i, u): i.update({self.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[self.T_NC_IE_N], input_endpoint[self.T_NC_IE_PR], input_endpoint[self.T_NC_IE_PO], input_endpoint[self.T_NC_IE_LP] ) ) return network_config
def get_network_config(self, azure_key_id, update): """ Return None if image type is vm and not update Public endpoint should be assigned in real time :param service: :return: """ azure_service = RequiredFeature("azure_service") if self.is_vm_image() and not update: return None cs = self.virtual_environment[self.T_CLOUD_SERVICE] nc = self.virtual_environment[self.T_NETWORK_CONFIG] network_config = ConfigurationSet() network_config.configuration_set_type = nc[self.T_CONFIGURATION_SET_TYPE] input_endpoints = nc[self.T_INPUT_ENDPOINTS] # avoid duplicate endpoint under same cloud service assigned_endpoints = azure_service.get_assigned_endpoints(azure_key_id, cs[self.SERVICE_NAME]) endpoints = map(lambda i: i[self.T_LOCAL_PORT], input_endpoints) unassigned_endpoints = map(str, find_unassigned_endpoints(endpoints, assigned_endpoints)) map(lambda (i, u): i.update({self.PORT: u}), zip(input_endpoints, unassigned_endpoints)) for input_endpoint in input_endpoints: network_config.input_endpoints.input_endpoints.append( ConfigurationSetInputEndpoint( input_endpoint[self.NAME], input_endpoint[self.PROTOCOL], input_endpoint[self.PORT], input_endpoint[self.T_LOCAL_PORT] ) ) return network_config
def __generate_endpoint(self, context): public_endpoints = find_unassigned_endpoints(context.private_endpoints, context.assigned_endpoints) self.log.debug('public_endpoints: %s' % public_endpoints) deployment_name = self.azure_adapter.get_deployment_name(context.azure_key_id, context.cloud_service_name, context.deployment_slot) network_config = self.azure_adapter.get_virtual_machine_network_config(context.azure_key_id, context.cloud_service_name, deployment_name, context.virtual_machine_name) # compose new network config to update new_network_config = add_endpoint_to_network_config(network_config, public_endpoints, context.private_endpoints) if new_network_config is None: return None try: result = self.azure_adapter.update_virtual_machine_network_config(context.azure_key_id, context.cloud_service_name, deployment_name, context.virtual_machine_name, new_network_config) except Exception as e: self.log.error(e) return None if not self.azure_adapter.wait_for_async(result.request_id, self.TICK, self.LOOP): self.log.error('wait for async fail') return None if not self.azure_adapter.wait_for_virtual_machine(context.azure_key_id, context.cloud_service_name, deployment_name, context.virtual_machine_name, self.TICK, self.LOOP, AVMStatus.READY_ROLE): self.log.error('%s [%s] not ready' % (AZURE_RESOURCE_TYPE.VIRTUAL_MACHINE, context.virtual_machine_name)) return None return public_endpoints