예제 #1
0
파일: servers.py 프로젝트: vgerak/synnefo
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
예제 #2
0
파일: servers.py 프로젝트: grnet/synnefo
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
예제 #3
0
파일: images.py 프로젝트: vkoukis/synnefo
def image_to_dict(image, detail=True):
    d = dict(id=image["id"], name=image["name"])
    if detail:
        d["updated"] = utils.isoformat(date_parse(image["updated_at"]))
        d["created"] = utils.isoformat(date_parse(image["created_at"]))
        d["status"] = "DELETED" if image["deleted_at"] else "ACTIVE"
        d["progress"] = 100 if image["status"] == "available" else 0
        d["user_id"] = image["owner"]
        d["tenant_id"] = image["owner"]
        d["links"] = util.image_to_links(image["id"])
        if image["properties"]:
            d["metadata"] = image["properties"]
        else:
            d["metadata"] = {}
    return d
예제 #4
0
def image_to_dict(image, detail=True):
    d = dict(id=image['id'], name=image['name'])
    if detail:
        d['updated'] = utils.isoformat(date_parse(image['updated_at']))
        d['created'] = utils.isoformat(date_parse(image['created_at']))
        d['status'] = 'DELETED' if image['deleted_at'] else 'ACTIVE'
        d['progress'] = 100 if image['status'] == 'available' else 0
        d['user_id'] = image['owner']
        d['tenant_id'] = image['owner']
        d['links'] = util.image_to_links(image["id"])
        if image["properties"]:
            d['metadata'] = image['properties']
        else:
            d['metadata'] = {}
    return d
예제 #5
0
파일: images.py 프로젝트: antonis-m/synnefo
def image_to_dict(image, detail=True):
    d = dict(id=image['id'], name=image['name'])
    if detail:
        d['updated'] = utils.isoformat(date_parse(image['updated_at']))
        d['created'] = utils.isoformat(date_parse(image['created_at']))
        d['status'] = 'DELETED' if image['deleted_at'] else 'ACTIVE'
        d['progress'] = 100 if image['status'] == 'available' else 0
        d['user_id'] = image['owner']
        d['tenant_id'] = image['owner']
        d['links'] = util.image_to_links(image["id"])
        if image["properties"]:
            d['metadata'] = image['properties']
        else:
            d['metadata'] = {}
    return d
예제 #6
0
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
예제 #7
0
def image_to_dict(image, detail=True):
    d = dict(id=image['id'], name=image['name'])
    if detail:
        d['updated'] = utils.isoformat(date_parse(image['updated_at']))
        d['created'] = utils.isoformat(date_parse(image['created_at']))
        img_status = image.get("status", "").upper()
        status = API_STATUS_FROM_IMAGE_STATUS.get(img_status, "UNKNOWN")
        d['status'] = status
        d['progress'] = 100 if status == 'ACTIVE' else 0
        d['user_id'] = image['owner']
        d['tenant_id'] = image['owner']
        d['public'] = image["is_public"]
        d['links'] = util.image_to_links(image["id"])
        if image["properties"]:
            d['metadata'] = image['properties']
        else:
            d['metadata'] = {}
        d["is_snapshot"] = image["is_snapshot"]
    return d
예제 #8
0
파일: images.py 프로젝트: grnet/synnefo
def image_to_dict(image, detail=True):
    d = dict(id=image['id'], name=image['name'])
    if detail:
        d['updated'] = utils.isoformat(date_parse(image['updated_at']))
        d['created'] = utils.isoformat(date_parse(image['created_at']))
        img_status = image.get("status", "").upper()
        status = API_STATUS_FROM_IMAGE_STATUS.get(img_status, "UNKNOWN")
        d['status'] = status
        d['progress'] = 100 if status == 'ACTIVE' else 0
        d['user_id'] = image['owner']
        d['tenant_id'] = image['owner']
        d['public'] = image["is_public"]
        d['links'] = util.image_to_links(image["id"])
        if image["properties"]:
            d['metadata'] = image['properties']
        else:
            d['metadata'] = {}
        d["is_snapshot"] = image["is_snapshot"]
    return d
예제 #9
0
파일: servers.py 프로젝트: cstavr/synnefo
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