def vm_to_dict(vm, detail=False): d = dict(id=vm.id, name=vm.name) d['links'] = util.vm_to_links(vm.id) if detail: d['user_id'] = vm.userid d['tenant_id'] = vm.project d['shared_to_project'] = vm.shared_to_project d['status'] = logic_utils.get_rsapi_state(vm) d['SNF:task_state'] = logic_utils.get_task_state(vm) d['progress'] = 100 if d['status'] == 'ACTIVE' else vm.buildpercentage d['hostId'] = vm.hostid d['updated'] = utils.isoformat(vm.updated) d['created'] = utils.isoformat(vm.created) d['flavor'] = { "id": vm.flavor_id, "links": util.flavor_to_links(vm.flavor_id) } d['image'] = { "id": vm.imageid, "links": util.image_to_links(vm.imageid) } d['suspended'] = vm.suspended metadata = dict((m.meta_key, m.meta_value) for m in vm.metadata.all()) d['metadata'] = metadata nics = vm.nics.all() active_nics = filter(lambda nic: nic.state == "ACTIVE", nics) active_nics.sort(key=lambda nic: nic.id) attachments = map(nic_to_attachments, active_nics) d['attachments'] = attachments d['addresses'] = attachments_to_addresses(attachments) d['volumes'] = [ v.id for v in vm.volumes.filter(deleted=False).order_by('id') ] # include the latest vm diagnostic, if set diagnostic = vm.get_last_diagnostic() if diagnostic: d['diagnostics'] = diagnostics_to_dict([diagnostic]) else: d['diagnostics'] = [] # Fixed d["security_groups"] = [{"name": "default"}] key_names = json.loads(vm.key_names) d["key_name"] = key_names[0] if len(key_names) > 0 else None d["SNF:key_names"] = key_names d["config_drive"] = "" d["accessIPv4"] = "" d["accessIPv6"] = "" fqdn = get_server_fqdn(vm, active_nics) d["SNF:fqdn"] = fqdn d["SNF:port_forwarding"] = get_server_port_forwarding( vm, active_nics, fqdn) d['deleted'] = vm.deleted d['SNF:rescue'] = vm.rescue return d
def flavor_to_dict(flavor, detail=True): d = {'id': flavor.id, 'name': flavor.name} d['links'] = util.flavor_to_links(flavor.id) if detail: d['ram'] = flavor.ram d['disk'] = flavor.disk d['vcpus'] = flavor.cpu d['SNF:disk_template'] = flavor.disk_template return d
def flavor_to_dict(flavor, detail=True): d = {'id': flavor.id, 'name': flavor.name} d['links'] = util.flavor_to_links(flavor.id) if detail: d['ram'] = flavor.ram d['disk'] = flavor.disk d['vcpus'] = flavor.cpu d['SNF:disk_template'] = flavor.volume_type.disk_template d['SNF:volume_type'] = flavor.volume_type_id d['SNF:allow_create'] = flavor.allow_create return d
def vm_to_dict(vm, detail=False): d = dict(id=vm.id, name=vm.name) d['links'] = util.vm_to_links(vm.id) if detail: d['user_id'] = vm.userid d['tenant_id'] = vm.project d['shared_to_project'] = vm.shared_to_project d['status'] = logic_utils.get_rsapi_state(vm) d['SNF:task_state'] = logic_utils.get_task_state(vm) d['progress'] = 100 if d['status'] == 'ACTIVE' else vm.buildpercentage d['hostId'] = vm.hostid d['updated'] = utils.isoformat(vm.updated) d['created'] = utils.isoformat(vm.created) d['flavor'] = {"id": vm.flavor_id, "links": util.flavor_to_links(vm.flavor_id)} d['image'] = {"id": vm.imageid, "links": util.image_to_links(vm.imageid)} d['suspended'] = vm.suspended metadata = dict((m.meta_key, m.meta_value) for m in vm.metadata.all()) d['metadata'] = metadata nics = vm.nics.all() active_nics = filter(lambda nic: nic.state == "ACTIVE", nics) active_nics.sort(key=lambda nic: nic.id) attachments = map(nic_to_attachments, active_nics) d['attachments'] = attachments d['addresses'] = attachments_to_addresses(attachments) d['volumes'] = [v.id for v in vm.volumes.filter(deleted=False) .order_by('id')] # include the latest vm diagnostic, if set diagnostic = vm.get_last_diagnostic() if diagnostic: d['diagnostics'] = diagnostics_to_dict([diagnostic]) else: d['diagnostics'] = [] # Fixed d["security_groups"] = [{"name": "default"}] key_names = json.loads(vm.key_names) d["key_name"] = key_names[0] if len(key_names) > 0 else None d["SNF:key_names"] = key_names d["config_drive"] = "" d["accessIPv4"] = "" d["accessIPv6"] = "" fqdn = get_server_fqdn(vm, active_nics) d["SNF:fqdn"] = fqdn d["SNF:port_forwarding"] = get_server_port_forwarding(vm, active_nics, fqdn) d['deleted'] = vm.deleted d['SNF:rescue'] = vm.rescue return d
def flavor_to_dict(flavor, detail=True, projects=[]): d = {'id': flavor.id, 'name': flavor.name} d['links'] = util.flavor_to_links(flavor.id) if detail: d['ram'] = flavor.ram d['disk'] = flavor.disk d['vcpus'] = flavor.cpu d['os-flavor-access:is_public'] = flavor.public d['SNF:disk_template'] = flavor.volume_type.disk_template d['SNF:volume_type'] = flavor.volume_type_id d['SNF:allow_create'] = flavor.allow_create d['SNF:flavor-access'] = [a.project for a in flavor.access.all() if a.project in projects] return d
def flavor_to_dict(flavor, detail=True, projects=[]): d = {'id': flavor.id, 'name': flavor.name} d['links'] = util.flavor_to_links(flavor.id) if detail: d['ram'] = flavor.ram d['disk'] = flavor.disk d['vcpus'] = flavor.cpu d['os-flavor-access:is_public'] = flavor.public d['SNF:disk_template'] = flavor.volume_type.disk_template d['SNF:volume_type'] = flavor.volume_type_id d['SNF:allow_create'] = flavor.allow_create d['SNF:flavor-access'] = [ a.project for a in flavor.access.all() if a.project in projects ] return d
def vm_to_dict(vm, detail=False): d = dict(id=vm.id, name=vm.name) d['links'] = util.vm_to_links(vm.id) if detail: d['user_id'] = vm.userid d['tenant_id'] = vm.userid d['status'] = get_rsapi_state(vm) d['progress'] = 100 if get_rsapi_state(vm) == 'ACTIVE' \ else vm.buildpercentage d['hostId'] = vm.hostid d['updated'] = utils.isoformat(vm.updated) d['created'] = utils.isoformat(vm.created) d['flavor'] = { "id": vm.flavor.id, "links": util.flavor_to_links(vm.flavor.id) } d['image'] = { "id": vm.imageid, "links": util.image_to_links(vm.imageid) } d['suspended'] = vm.suspended metadata = dict((m.meta_key, m.meta_value) for m in vm.metadata.all()) d['metadata'] = metadata vm_nics = vm.nics.filter(state="ACTIVE").order_by("index") attachments = map(nic_to_dict, vm_nics) d['attachments'] = attachments d['addresses'] = nics_to_addresses(vm_nics) # include the latest vm diagnostic, if set diagnostic = vm.get_last_diagnostic() if diagnostic: d['diagnostics'] = diagnostics_to_dict([diagnostic]) else: d['diagnostics'] = [] # Fixed d["security_groups"] = [{"name": "default"}] d["key_name"] = None d["config_drive"] = "" d["accessIPv4"] = "" d["accessIPv6"] = "" return d
def vm_to_dict(vm, detail=False): d = dict(id=vm.id, name=vm.name) d['links'] = util.vm_to_links(vm.id) if detail: d['user_id'] = vm.userid d['tenant_id'] = vm.userid d['status'] = get_rsapi_state(vm) d['progress'] = 100 if get_rsapi_state(vm) == 'ACTIVE' \ else vm.buildpercentage d['hostId'] = vm.hostid d['updated'] = utils.isoformat(vm.updated) d['created'] = utils.isoformat(vm.created) d['flavor'] = {"id": vm.flavor.id, "links": util.flavor_to_links(vm.flavor.id)} d['image'] = {"id": vm.imageid, "links": util.image_to_links(vm.imageid)} d['suspended'] = vm.suspended metadata = dict((m.meta_key, m.meta_value) for m in vm.metadata.all()) d['metadata'] = metadata vm_nics = vm.nics.filter(state="ACTIVE").order_by("index") attachments = map(nic_to_dict, vm_nics) d['attachments'] = attachments d['addresses'] = nics_to_addresses(vm_nics) # include the latest vm diagnostic, if set diagnostic = vm.get_last_diagnostic() if diagnostic: d['diagnostics'] = diagnostics_to_dict([diagnostic]) else: d['diagnostics'] = [] # Fixed d["security_groups"] = [{"name": "default"}] d["key_name"] = None d["config_drive"] = "" d["accessIPv4"] = "" d["accessIPv6"] = "" return d