示例#1
0
    def get_compute_data(self, instance, disks, zone_info):
        '''
            {
                'keypair': StringType(default="")
                'az':StringType()                       # zone_name
                'instance_id': StringType()
                'instance_name': StringType(default='')
                'instance_state':StringType(choices=('STAGING', 'RUNNING', 'STOPPING', 'REPAIRING'))
                'instance_type' : StringType()
                'account' : StringType()                  # Project_id
                'image' : StringType()
                'launched_at' : DateTimeType()
                'security_groups': []
                'tags' = DictType(StringType, default={})
            }
        '''

        compute_data = {
            'keypair': '',
            'public_ip_address': self._get_public_ip_address(instance),
            'az': zone_info.get('zone', ''),  # zone_name
            'instance_id': instance.get('id'),
            'instance_name': instance.get('name', ''),
            'instance_state': instance.get('status'),
            'instance_type': self._get_instance_type(instance),
            'account': zone_info.get('project_id', ''),
            'image': self._get_images(instance, disks),
            'launched_at': instance.get('creationTimestamp'),
            'tags': self._get_tags_only_string_values(instance)
        }

        return Compute(compute_data)
示例#2
0
    def get_compute_data(self, vm, resource_group_name, network_security_groups, subscription_id):
        vm_info = self.azure_vm_connector.get_vm(resource_group_name, vm.name)
        compute_data = {
            'keypair': self.get_keypair(vm.os_profile.linux_configuration),
            'instance_state': self.get_instance_state(vm_info.instance_view.statuses),
            'instance_type': vm.hardware_profile.vm_size,
            'launched_at': self.get_launched_time(vm_info.instance_view.statuses),
            'instance_id': vm.id,
            'instance_name': vm.name,
            'security_groups': self.get_security_groups(vm.network_profile.network_interfaces, network_security_groups),
            'image': self.get_image_detail(vm.location, vm.storage_profile.image_reference, subscription_id),
            'tags': {
                'vm_id': vm.vm_id
            }
        }

        if vm.zones:
            compute_data.update({
                'az': f'{vm.location}-{vm.zones[0]}'
            })
        else:
            compute_data.update({
                'az': vm.location
            })

        return Compute(compute_data, strict=False)
 def get_compute_data(instance, primary_public_ip):
     compute_data = {
         "keypair":
         instance.get("KeyPairName", ""),
         "az":
         instance.get("ZoneId", ""),
         "instance_state":
         instance.get("Status").upper(),
         "instance_type":
         instance.get("InstanceType", ""),
         "launched_at":
         instance.get("CreationTime"),
         "instance_id":
         instance.get("InstanceId"),
         "instance_name":
         instance.get("InstanceName"),
         "region_name":
         instance.get("RegionId"),
         "security_groups":
         instance.get("SecurityGroupIds", {}).get("SecurityGroupId", []),
         "image":
         instance.get("ImageId")
     }
     if primary_public_ip:
         compute_data.update(
             {"tags": {
                 "primary_public_ip": primary_public_ip
             }})
     return Compute(compute_data, strict=False)
示例#4
0
    def get_compute_data(self, instance, image):
        compute_data = {
            # 'eip': self.match_eips_from_instance_id(instance.get('InstanceId'), eips),
            'keypair': instance.get('KeyName', ''),
            'az': instance.get('Placement', {}).get('AvailabilityZone', ''),
            'instance_state': instance.get('State', {}).get('Name').upper(),
            'instance_type': instance.get('InstanceType', ''),
            'launched_at': instance.get('LaunchTime'),
            'instance_id': instance.get('InstanceId'),
            'instance_name': self.generate_name(instance),
            'security_groups': self._get_security_groups(instance),
            'image': image.get('Name', '')
        }

        return Compute(compute_data, strict=False)