示例#1
0
 def update_eip_runtime(self):
     eip_instance = self.get_eip()
     eip_id = eip_instance.runtime_properties[common_constants.EXTERNAL_ID]
     eip_instance.runtime_properties = {}
     request_body = {'AllocationId.1': eip_id}
     eip_info = Helper().execute_request('eip', 'describe_addresses',
                                         request_body)['AddressesSet'][0]
     eip_instance.runtime_properties[
         common_constants.EXTERNAL_ID] = eip_info['AllocationId']
     eip_instance.runtime_properties[
         common_constants.EIP_ADDRESS] = eip_info['PublicIp']
     eip_instance.runtime_properties[
         common_constants.EIP_STATUS] = eip_info['State']
     eip_instance.runtime_properties[
         ksyun_constants.KS_EIP_TYPE] = eip_info.get('InstanceType')
     instance_id = eip_info.get('InstanceId')
     if instance_id and eip_info.get('InstanceType') == 'Ipfwd':
         vm_info = self.describe_vm(eip_info['InstanceId'])
         if vm_info:
             eip_instance.runtime_properties[
                 common_constants.
                 EIP_RELATED_INSTANCE_ID] = eip_info['InstanceId']
             eip_instance.runtime_properties[
                 common_constants.EIP_RELATED_INSTANCE_NAME] = vm_info.get(
                     'InstanceName')
     eip_instance.update()
示例#2
0
 def create(self):
     slb_id = self.get_related_slb()
     if not slb_id:
         raise NonRecoverableError(
             'Unable to obtain load balancer ID, single node deployment is not supported!'
         )
     listener_params = self.prepare_params(slb_id)
     ctx.logger.info(
         'Attempting to create listeners parameters: {0}'.format(
             listener_params))
     result = Helper().execute_request('slb', 'create_listeners',
                                       listener_params)
     listener_id = result.get('ListenerId')
     if not listener_id:
         raise NonRecoverableError('Listener create failed!')
     self.update_listener_runtime(listener_id)
     ctx.logger.info(
         'Create listeners: {0} successfully'.format(listener_id))
     health_check_params = self.get_health_check_params(listener_id)
     ctx.logger.info(
         'Attempting to create health check parameters: {0}'.format(
             health_check_params))
     res = Helper().execute_request('slb', 'configure_health_check',
                                    health_check_params)
     health_check_id = res.get('HealthCheckId')
     if health_check_id:
         self.update_listener_runtime(listener_id)
         ctx.logger.info(
             'Create listeners: {0} and health check: {1} successfully.'.
             format(listener_id, health_check_id))
     else:
         raise NonRecoverableError('Create health check failed!')
示例#3
0
 def describe_instance_cloud_volumes(self):
     instance_id = ctx.instance.runtime_properties['external_id']
     cloud_volumes = Helper().execute_request('ebs',
                                              'describe_instance_volumes',
                                              {"InstanceId": instance_id})
     cloud_volumes = cloud_volumes.get('Attachments') or []
     return cloud_volumes
示例#4
0
 def describe_instance_local_volumes(self):
     instance_id = ctx.instance.runtime_properties['external_id']
     local_volumes = Helper().execute_request('kec',
                                              'describe_local_volumes',
                                              {"InstanceId": instance_id})
     local_volumes = local_volumes.get('LocalVolumeSet') or []
     return local_volumes
示例#5
0
 def update_eip_runtime(eip_id):
     ctx.instance.runtime_properties = {}
     request_body = {
         'AllocationId.1': eip_id
     }
     eip_obj = Helper().execute_request('eip', 'describe_addresses', request_body)['AddressesSet']
     if not eip_obj:
         return eip_obj
     eip_obj = eip_obj[0]
     ctx.instance.runtime_properties[common_constants.EXTERNAL_ID] = eip_obj['AllocationId']
     ctx.instance.runtime_properties[common_constants.EIP_ADDRESS] = eip_obj['PublicIp']
     ctx.instance.runtime_properties[common_constants.EIP_STATUS] = eip_obj['State']
     ctx.instance.runtime_properties[ksyun_constants.KS_EIP_TYPE] = eip_obj.get('InstanceType')
     instance_id = eip_obj.get('InstanceId')
     if instance_id and eip_obj.get('InstanceType') == 'Ipfwd':
         request_body = {
             'InstanceId.1': eip_obj['InstanceId']
         }
         instance_obj = Helper().execute_request('kec', 'describe_instances', request_body)['InstancesSet'][0]
         ctx.instance.runtime_properties[common_constants.EIP_RELATED_INSTANCE_ID] = eip_obj['InstanceId']
         ctx.instance.runtime_properties[common_constants.EIP_RELATED_INSTANCE_NAME] = instance_obj.get(
             'InstanceName')
示例#6
0
 def delete(self):
     listener_id = ctx.instance.runtime_properties.get(
         constants.EXTERNAL_ID)
     if not listener_id:
         ctx.logger.info('The listener was not created successfully')
         return
     request_body = {'ListenerId': listener_id}
     result = Helper().execute_request('slb', 'delete_listeners',
                                       request_body)
     if result.get('Return'):
         ctx.instance.runtime_properties = {}
         ctx.instance.update()
         ctx.logger.info(
             'Delete listeners: {0} successfully.'.format(listener_id))
     else:
         raise NonRecoverableError(
             'Delete listeners: {0} failed.'.format(listener_id))
示例#7
0
 def update_listener_runtime(listener_id):
     request_body = {'ListenerId.1': listener_id}
     result = Helper().execute_request('slb', 'describe_listeners',
                                       request_body)
     listeners_obj = result.get('ListenerSet')
     if listeners_obj:
         external_slb_id = listeners_obj[0].pop('LoadBalancerId')
         listener_obj = listeners_obj[0]
         ctx.instance.runtime_properties['external_id'] = listener_obj.get(
             'ListenerId')
         ctx.instance.runtime_properties[
             'external_name'] = listener_obj.get('ListenerName')
         ctx.instance.runtime_properties['status'] = listener_obj.get(
             'ListenerState')
         ctx.instance.runtime_properties[
             'external_slb_id'] = external_slb_id
         ctx.instance.runtime_properties.update(listener_obj)
         ctx.instance.update()
     else:
         ctx.logger.info('Listeners does not exist!')
示例#8
0
 def create(self):
     '''
     There will be two situations:
     1.EIP is to be created with no relationship
     2.EIP is to be created with instance and should be associate with instance
     '''
     if not convert2bool(self.resource_config.get('allocate_eip', True)):
         return
     if self.use_external_resource:
         self._create_external_eip()
         return
     resource_config = ctx.node.properties['resource_config']
     ctx.logger.info('Allocate Eip...resource_config:{}'.format(resource_config))
     request_body = {
         'BandWidth': validate_parameter('band_width', resource_config),
         'ChargeType': resource_config.get('charge_type', 'HourlyInstantSettlement'),
     }
     line_id = resource_config.get('line_id', None)
     if line_id:
         request_body['LineId'] = line_id
     ctx.logger.info('Allocate Eip...request_body:{}'.format(request_body))
     eip_obj = Helper().execute_request('eip', 'allocate_address', request_body)
     ctx.logger.info('Allocate Eip successfully....Eip info:{}'.format(eip_obj))
     self.update_eip_runtime(eip_obj.get('AllocationId'))
示例#9
0
 def describe_vm(self, instance_id):
     res = Helper().execute_request('kec', 'describe_instances',
                                    {"InstanceId.1": instance_id})
     return None if not res.get("InstancesSet") else res['InstancesSet'][0]