当前位置: 首页>>代码示例>>Python>>正文


Python util.get_vm函数代码示例

本文整理汇总了Python中synnefo.api.util.get_vm函数的典型用法代码示例。如果您正苦于以下问题:Python get_vm函数的具体用法?Python get_vm怎么用?Python get_vm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_vm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: server_stats

def server_stats(request, server_id):
    # Normal Response Codes: 200
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       itemNotFound (404),
    #                       overLimit (413)

    log.debug('server_stats %s', server_id)
    vm = util.get_vm(server_id, request.user_uniq)
    #secret = util.encrypt(vm.backend_vm_id)
    secret = vm.backend_vm_id      # XXX disable backend id encryption

    stats = {
        'serverRef': vm.id,
        'refresh': settings.STATS_REFRESH_PERIOD,
        'cpuBar': settings.CPU_BAR_GRAPH_URL % secret,
        'cpuTimeSeries': settings.CPU_TIMESERIES_GRAPH_URL % secret,
        'netBar': settings.NET_BAR_GRAPH_URL % secret,
        'netTimeSeries': settings.NET_TIMESERIES_GRAPH_URL % secret}

    if request.serialization == 'xml':
        data = render_to_string('server_stats.xml', stats)
    else:
        data = json.dumps({'stats': stats})

    return HttpResponse(data, status=200)
开发者ID:cstavr,项目名称:synnefo,代码行数:28,代码来源:servers.py

示例2: add

def add(request, net, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       buildInProgress (409),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       overLimit (413)

    if net.state != 'ACTIVE':
        raise faults.BuildInProgress('Network not active yet')

    server_id = args.get('serverRef', None)
    if not server_id:
        raise faults.BadRequest('Malformed Request.')

    vm = get_vm(server_id, request.user_uniq, non_suspended=True)

    address = None
    if net.dhcp:
        # Get a free IP from the address pool.
        try:
            address = get_network_free_address(net)
        except EmptyPool:
            raise faults.OverLimit('Network is full')

    log.info("Connecting VM %s to Network %s(%s)", vm, net, address)

    backend.connect_to_network(vm, net, address)
    return HttpResponse(status=202)
开发者ID:mpastyl,项目名称:websocket-console,代码行数:32,代码来源:actions.py

示例3: create_port

def create_port(credentials, network_id, machine_id=None,
                address=None, name="", security_groups=None,
                device_owner=None):
    user_id = credentials.userid
    vm = None
    if machine_id is not None:
        vm = util.get_vm(machine_id, credentials,
                         for_update=True, non_deleted=True, non_suspended=True)
        if vm.nics.count() == settings.GANETI_MAX_NICS_PER_INSTANCE:
            raise faults.BadRequest("Maximum ports per server limit reached")

    network = util.get_network(network_id, credentials,
                               non_deleted=True, for_update=True)

    ipaddress = None
    if network.public:
        # Creating a port to a public network is only allowed if the user has
        # already a floating IP address in this network which is specified
        # as the fixed IP address of the port
        if address is None:
            msg = ("'fixed_ips' attribute must contain a floating IP address"
                   " in order to connect to a public network.")
            raise faults.BadRequest(msg)
        ipaddress = util.get_floating_ip_by_address(credentials,
                                                    address,
                                                    for_update=True)
    port = _create_port(user_id, network, machine=vm, use_ipaddress=ipaddress,
                        name=name,
                        security_groups=security_groups,
                        device_owner=device_owner)

    log.info("User %s created port %s, network: %s, machine: %s, ip: %s",
             user_id, port.id, network, vm, ipaddress)
    return port
开发者ID:grnet,项目名称:synnefo,代码行数:34,代码来源:servers.py

示例4: resize

def resize(server_id, flavor_id, credentials=None, atomic_context=None):
    vm = util.get_vm(server_id, credentials,
                     for_update=True, non_deleted=True, non_suspended=True)
    flavor = util.get_flavor(flavor_id, credentials, include_deleted=False,
                             for_project=vm.project)
    action_fields = {"beparams": {"vcpus": flavor.cpu,
                                  "maxmem": flavor.ram}}
    with commands.ServerCommand(
            "RESIZE", server_id, credentials, atomic_context,
            action_fields=action_fields) as vm:
        old_flavor = vm.flavor
        # User requested the same flavor
        if old_flavor.id == flavor.id:
            raise faults.BadRequest("Server '%s' flavor is already '%s'."
                                    % (vm, flavor))
        # Check that resize can be performed
        if old_flavor.disk != flavor.disk:
            raise faults.BadRequest("Cannot change instance's disk size.")
        if old_flavor.volume_type_id != flavor.volume_type_id:
            raise faults.BadRequest("Cannot change instance's volume type.")

        log.info("Resizing VM from flavor '%s' to '%s", old_flavor, flavor)
        job_id = backend.resize_instance(
            vm, vcpus=flavor.cpu, memory=flavor.ram)
        vm.record_job(job_id)
        return vm
开发者ID:grnet,项目名称:synnefo,代码行数:26,代码来源:servers.py

示例5: create_metadata_item

def create_metadata_item(request, server_id, key):
    # Normal Response Code: 201
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       itemNotFound (404),
    #                       badRequest (400),
    #                       buildInProgress (409),
    #                       badMediaType(415),
    #                       overLimit (413)

    req = utils.get_request_dict(request)
    log.info('create_server_metadata_item %s %s %s', server_id, key, req)
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
    try:
        metadict = req['meta']
        assert isinstance(metadict, dict)
        assert len(metadict) == 1
        assert key in metadict
    except (KeyError, AssertionError):
        raise faults.BadRequest("Malformed request")

    meta, created = VirtualMachineMetadata.objects.get_or_create(
        meta_key=key,
        vm=vm)

    meta.meta_value = metadict[key]
    meta.save()
    vm.save()
    d = {meta.meta_key: meta.meta_value}
    return util.render_meta(request, d, status=201)
开发者ID:cstavr,项目名称:synnefo,代码行数:31,代码来源:servers.py

示例6: demux_server_action

def demux_server_action(request, server_id):
    req = utils.get_json_body(request)

    if not isinstance(req, dict) and len(req) != 1:
        raise faults.BadRequest("Malformed request")

    # Do not allow any action on deleted or suspended VMs
    vm = util.get_vm(server_id, request.user_uniq, request.user_projects,
                     for_update=True,  non_deleted=True, non_suspended=True)

    try:
        action = req.keys()[0]
    except IndexError:
        raise faults.BadRequest("Malformed Request.")

    log.debug("User: %s, VM: %s, Action: %s Request: %s",
              request.user_uniq, server_id, action, req)

    if not isinstance(action, basestring):
        raise faults.BadRequest("Malformed Request. Invalid action.")

    if key_to_action(action) not in [x[0] for x in VirtualMachine.ACTIONS]:
        if action not in ARBITRARY_ACTIONS:
            raise faults.BadRequest("Action %s not supported" % action)
    action_args = utils.get_attribute(req, action, required=True,
                                      attr_type=dict)

    return server_actions[action](request, vm, action_args)
开发者ID:gvsurenderreddy,项目名称:synnefo-1,代码行数:28,代码来源:servers.py

示例7: update_metadata

def update_metadata(request, server_id):
    # Normal Response Code: 201
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       buildInProgress (409),
    #                       badMediaType(415),
    #                       overLimit (413)

    req = utils.get_request_dict(request)
    log.info('update_server_metadata %s %s', server_id, req)
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
    metadata = utils.get_attribute(req, "metadata", required=True,
                                   attr_type=dict)

    for key, val in metadata.items():
        if not isinstance(key, (basestring, int)) or\
           not isinstance(val, (basestring, int)):
            raise faults.BadRequest("Malformed Request. Invalid metadata.")
        meta, created = vm.metadata.get_or_create(meta_key=key)
        meta.meta_value = val
        meta.save()

    vm.save()
    vm_meta = dict((m.meta_key, m.meta_value) for m in vm.metadata.all())
    return util.render_metadata(request, vm_meta, status=201)
开发者ID:antonis-m,项目名称:synnefo,代码行数:27,代码来源:servers.py

示例8: remove

def remove(request, net, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       overLimit (413)

    try:  # attachment string: nic-<vm-id>-<nic-index>
        server_id = args.get('attachment', None).split('-')[1]
        nic_index = args.get('attachment', None).split('-')[2]
    except AttributeError:
        raise faults.BadRequest("Malformed Request")
    except IndexError:
        raise faults.BadRequest('Malformed Network Interface Id')

    if not server_id or not nic_index:
        raise faults.BadRequest('Malformed Request.')

    vm = get_vm(server_id, request.user_uniq, non_suspended=True)
    nic = get_nic_from_index(vm, nic_index)

    log.info("Removing NIC %s from VM %s", str(nic.index), vm)

    if nic.dirty:
        raise faults.BuildInProgress('Machine is busy.')
    else:
        vm.nics.all().update(dirty=True)

    backend.disconnect_from_network(vm, nic)
    return HttpResponse(status=202)
开发者ID:mpastyl,项目名称:websocket-console,代码行数:33,代码来源:actions.py

示例9: remove

def remove(request, net, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       overLimit (413)

    attachment = args.get("attachment")
    if attachment is None:
        raise faults.BadRequest("Missing 'attachment' attribute.")
    try:
        nic_id = int(attachment)
    except (ValueError, TypeError):
        raise faults.BadRequest("Invalid 'attachment' attribute.")

    nic = util.get_nic(nic_id=nic_id)
    server_id = nic.machine_id
    vm = util.get_vm(server_id, request.user_uniq, request.user_projects, non_suspended=True,
                     for_update=True, non_deleted=True)

    servers.disconnect(vm, nic)

    log.info("User %s disconnected VM %s to network %s, port: %s",
             request.user_uniq, vm.id, network.id, nic.id)

    return HttpResponse(status=202)
开发者ID:gvsurenderreddy,项目名称:synnefo-1,代码行数:29,代码来源:servers.py

示例10: update_server_name

def update_server_name(request, server_id):
    # Normal Response Code: 204
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       buildInProgress (409),
    #                       overLimit (413)

    req = utils.get_request_dict(request)
    log.info('update_server_name %s %s', server_id, req)

    try:
        name = req['server']['name']
    except (TypeError, KeyError):
        raise faults.BadRequest("Malformed request")

    vm = util.get_vm(server_id, request.user_uniq, for_update=True,
                     non_suspended=True)
    vm.name = name
    vm.save()

    return HttpResponse(status=204)
开发者ID:cstavr,项目名称:synnefo,代码行数:25,代码来源:servers.py

示例11: update_metadata

def update_metadata(request, server_id):
    # Normal Response Code: 201
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       buildInProgress (409),
    #                       badMediaType(415),
    #                       overLimit (413)

    req = utils.get_request_dict(request)
    log.info('update_server_metadata %s %s', server_id, req)
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
    try:
        metadata = req['metadata']
        assert isinstance(metadata, dict)
    except (KeyError, AssertionError):
        raise faults.BadRequest("Malformed request")

    for key, val in metadata.items():
        meta, created = vm.metadata.get_or_create(meta_key=key)
        meta.meta_value = val
        meta.save()

    vm.save()
    vm_meta = dict((m.meta_key, m.meta_value) for m in vm.metadata.all())
    return util.render_metadata(request, vm_meta, status=201)
开发者ID:cstavr,项目名称:synnefo,代码行数:27,代码来源:servers.py

示例12: update_server_name

def update_server_name(request, server_id):
    # Normal Response Code: 204
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       buildInProgress (409),
    #                       overLimit (413)

    req = utils.get_json_body(request)
    log.debug("User: %s, VM: %s, Action: rename, Request: %s",
               request.user_uniq, server_id, req)

    req = utils.get_attribute(req, "server", attr_type=dict, required=True)
    name = utils.get_attribute(req, "name", attr_type=basestring,
                               required=True)

    vm = util.get_vm(server_id, request.user_uniq, request.user_projects,
                     for_update=True, non_suspended=True, non_deleted=True)

    servers.rename(vm, new_name=name)

    log.info("User %s renamed server %s", request.user_uniq, vm.id)

    return HttpResponse(status=204)
开发者ID:gvsurenderreddy,项目名称:synnefo-1,代码行数:27,代码来源:servers.py

示例13: detach_volume

def detach_volume(server_id, volume_id, credentials):
    user_id = credentials.userid
    vm = util.get_vm(server_id, credentials, for_update=True, non_deleted=True)
    volume = get_volume(credentials, volume_id,
                        for_update=True, non_deleted=True,
                        exception=faults.BadRequest)
    server_attachments.detach_volume(vm, volume)
    log.info("User %s detached volume %s to VM %s", user_id, volume.id, vm.id)
开发者ID:grnet,项目名称:synnefo,代码行数:8,代码来源:servers.py

示例14: get_server_diagnostics

def get_server_diagnostics(request, server_id):
    """
    Virtual machine diagnostics api view.
    """
    log.debug('server_diagnostics %s', server_id)
    vm = util.get_vm(server_id, request.user_uniq)
    diagnostics = diagnostics_to_dict(vm.diagnostics.all())
    return render_diagnostics(request, diagnostics)
开发者ID:cstavr,项目名称:synnefo,代码行数:8,代码来源:servers.py

示例15: detach_volume

def detach_volume(request, server_id, volume_id):
    log.debug("detach_volume server_id %s volume_id", server_id, volume_id)
    user_id = request.user_uniq
    vm = util.get_vm(server_id, user_id, for_update=True, non_deleted=True)
    volume = get_volume(user_id, volume_id, for_update=True, non_deleted=True,
                        exception=faults.BadRequest)
    vm = server_attachments.detach_volume(vm, volume)
    # TODO: Check volume state, send job to detach volume
    return HttpResponse(status=202)
开发者ID:AthinaB,项目名称:synnefo,代码行数:9,代码来源:servers.py


注:本文中的synnefo.api.util.get_vm函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。