Example #1
0
File: servers.py Project: yosh/nova
def _translate_detail_keys(inst):
    """ Coerces into dictionary format, mapping everything to Rackspace-like
    attributes for return"""
    power_mapping = {
        None: 'build',
        power_state.NOSTATE: 'build',
        power_state.RUNNING: 'active',
        power_state.BLOCKED: 'active',
        power_state.SUSPENDED: 'suspended',
        power_state.PAUSED: 'paused',
        power_state.SHUTDOWN: 'active',
        power_state.SHUTOFF: 'active',
        power_state.CRASHED: 'error',
        power_state.FAILED: 'error'}
    inst_dict = {}

    mapped_keys = dict(status='state', imageId='image_id',
        flavorId='instance_type', name='display_name', id='id')

    for k, v in mapped_keys.iteritems():
        inst_dict[k] = inst[v]

    inst_dict['status'] = power_mapping[inst_dict['status']]
    inst_dict['addresses'] = dict(public=[], private=[])

    # grab single private fixed ip
    private_ips = utils.get_from_path(inst, 'fixed_ip/address')
    inst_dict['addresses']['private'] = private_ips

    # grab all public floating ips
    public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address')
    inst_dict['addresses']['public'] = public_ips

    # Return the metadata as a dictionary
    metadata = {}
    for item in inst['metadata']:
        metadata[item['key']] = item['value']
    inst_dict['metadata'] = metadata

    inst_dict['hostId'] = ''
    if inst['host']:
        inst_dict['hostId'] = hashlib.sha224(inst['host']).hexdigest()

    return dict(server=inst_dict)
Example #2
0
 def build_private_parts(self, inst):
     return utils.get_from_path(inst, 'fixed_ips/address')
Example #3
0
 def build_public_parts(self, inst):
     return utils.get_from_path(inst, 'fixed_ips/floating_ips/address')
Example #4
0
 def build(self, inst):
     private_ips = utils.get_from_path(inst, 'fixed_ip/address')
     private_ips = [dict(version=4, addr=a) for a in private_ips]
     public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address')
     public_ips = [dict(version=4, addr=a) for a in public_ips]
     return dict(public=public_ips, private=private_ips)
Example #5
0
 def build(self, inst):
     private_ips = utils.get_from_path(inst, 'fixed_ip/address')
     public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address')
     return dict(public=public_ips, private=private_ips)
Example #6
0
 def build_private_parts(self, inst):
     return utils.get_from_path(inst, 'fixed_ips/address')
Example #7
0
 def build_public_parts(self, inst):
     return utils.get_from_path(inst, 'fixed_ips/floating_ips/address')
Example #8
0
 def build(self, inst):
     private_ips = utils.get_from_path(inst, 'fixed_ip/address')
     private_ips = [dict(version=4, addr=a) for a in private_ips]
     public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address')
     public_ips = [dict(version=4, addr=a) for a in public_ips]
     return dict(public=public_ips, private=private_ips)
Example #9
0
 def build(self, inst):
     private_ips = utils.get_from_path(inst, 'fixed_ip/address')
     public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address')
     return dict(public=public_ips, private=private_ips)