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


Python models.pooled_rapi_client函数代码示例

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


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

示例1: get_ganeti_nodes

def get_ganeti_nodes(backend=None, bulk=False):
    nodes = []
    for backend in get_backends(backend):
        with pooled_rapi_client(backend) as client:
            nodes.append(client.GetNodes(bulk=bulk))

    return reduce(list.__add__, nodes, [])
开发者ID:mpastyl,项目名称:websocket-console,代码行数:7,代码来源:backend.py

示例2: set_firewall_profile

def set_firewall_profile(vm, profile, nic):
    uuid = nic.backend_uuid
    try:
        tag = _firewall_tags[profile] % uuid
    except KeyError:
        raise ValueError("Unsopported Firewall Profile: %s" % profile)

    log.debug("Setting tag of VM %s, NIC %s, to %s", vm, nic, profile)

    with pooled_rapi_client(vm) as client:
        # Delete previous firewall tags
        old_tags = client.GetInstanceTags(vm.backend_vm_id)
        delete_tags = [(t % uuid) for t in _firewall_tags.values()
                       if (t % uuid) in old_tags]
        if delete_tags:
            client.DeleteInstanceTags(vm.backend_vm_id, delete_tags,
                                      dry_run=settings.TEST)

        if profile != "DISABLED":
            client.AddInstanceTags(vm.backend_vm_id, [tag],
                                   dry_run=settings.TEST)

        # XXX NOP ModifyInstance call to force process_net_status to run
        # on the dispatcher
        os_name = settings.GANETI_CREATEINSTANCE_KWARGS['os']
        client.ModifyInstance(vm.backend_vm_id,
                              os_name=os_name)
    return None
开发者ID:apyrgio,项目名称:synnefo,代码行数:28,代码来源:backend.py

示例3: connect_to_network

def connect_to_network(vm, nic):
    network = nic.network
    backend = vm.backend
    bnet, depend_jobs = ensure_network_is_active(backend, network.id)

    depends = create_job_dependencies(depend_jobs)

    nic = {'name': nic.backend_uuid,
           'network': network.backend_id,
           'ip': nic.ipv4_address}

    log.debug("Adding NIC %s to VM %s", nic, vm)

    kwargs = {
        "instance": vm.backend_vm_id,
        "nics": [("add", "-1", nic)],
        "depends": depends,
    }
    if vm.backend.use_hotplug():
        kwargs["hotplug_if_possible"] = True
    if settings.TEST:
        kwargs["dry_run"] = True

    with pooled_rapi_client(vm) as client:
        return client.ModifyInstance(**kwargs)
开发者ID:apyrgio,项目名称:synnefo,代码行数:25,代码来源:backend.py

示例4: get_instance_console

def get_instance_console(vm):
    # RAPI GetInstanceConsole() returns endpoints to the vnc_bind_address,
    # which is a cluster-wide setting, either 0.0.0.0 or 127.0.0.1, and pretty
    # useless (see #783).
    #
    # Until this is fixed on the Ganeti side, construct a console info reply
    # directly.
    #
    # WARNING: This assumes that VNC runs on port network_port on
    #          the instance's primary node, and is probably
    #          hypervisor-specific.
    #
    log.debug("Getting console for vm %s", vm)

    console = {}
    console['kind'] = 'vnc'

    with pooled_rapi_client(vm) as client:
        i = client.GetInstance(vm.backend_vm_id)

    if vm.backend.hypervisor == "kvm" and i['hvparams']['serial_console']:
        raise Exception("hv parameter serial_console cannot be true")
    console['host'] = i['pnode']
    console['port'] = i['network_port']

    return console
开发者ID:apyrgio,项目名称:synnefo,代码行数:26,代码来源:backend.py

示例5: stale_servers_in_db

def stale_servers_in_db(D, G):
    idD = set(D.keys())
    idG = set(G.keys())

    stale = set()
    for i in idD - idG:
        if D[i] == 'BUILD':
            vm = VirtualMachine.objects.get(id=i)
            if needs_reconciliation(vm):
                with pooled_rapi_client(vm) as c:
                    try:
                        job_status = c.GetJobStatus(vm.backendjobid)['status']
                        if job_status in ('queued', 'waiting', 'running'):
                            # Server is still building in Ganeti
                            continue
                        else:
                            c.GetInstance(utils.id_to_instance_name(i))
                            # Server has just been created in Ganeti
                            continue
                    except GanetiApiError:
                        stale.add(i)
        else:
            stale.add(i)

    return stale
开发者ID:mpastyl,项目名称:websocket-console,代码行数:25,代码来源:reconciliation.py

示例6: _create_network

def _create_network(network, backend):
    """Create a network."""

    network_type = network.public and 'public' or 'private'

    tags = network.backend_tag
    if network.dhcp:
        tags.append('nfdhcpd')

    if network.public:
        conflicts_check = True
    else:
        conflicts_check = False

    try:
        bn = BackendNetwork.objects.get(network=network, backend=backend)
        mac_prefix = bn.mac_prefix
    except BackendNetwork.DoesNotExist:
        raise Exception("BackendNetwork for network '%s' in backend '%s'"
                        " does not exist" % (network.id, backend.id))

    with pooled_rapi_client(backend) as client:
        return client.CreateNetwork(network_name=network.backend_id,
                                    network=network.subnet,
                                    network6=network.subnet6,
                                    gateway=network.gateway,
                                    gateway6=network.gateway6,
                                    network_type=network_type,
                                    mac_prefix=mac_prefix,
                                    conflicts_check=conflicts_check,
                                    tags=tags)
开发者ID:mpastyl,项目名称:websocket-console,代码行数:31,代码来源:backend.py

示例7: set_firewall_profile

def set_firewall_profile(vm, profile):
    try:
        tag = _firewall_tags[profile]
    except KeyError:
        raise ValueError("Unsopported Firewall Profile: %s" % profile)

    try:
        public_nic = vm.nics.filter(network__public=True)[0]
    except IndexError:
        public_nic = None

    log.debug("Setting tag of VM %s to %s", vm, profile)

    with pooled_rapi_client(vm) as client:
        # Delete all firewall tags
        for t in _firewall_tags.values():
            client.DeleteInstanceTags(vm.backend_vm_id, [t],
                                      dry_run=settings.TEST)
            if public_nic is not None:
                tag_with_name = t.replace("0", public_nic.backend_uuid)
                client.DeleteInstanceTags(vm.backend_vm_id, [tag_with_name],
                                          dry_run=settings.TEST)

        client.AddInstanceTags(vm.backend_vm_id, [tag], dry_run=settings.TEST)
        if public_nic is not None:
            tag_with_name = tag.replace("0", public_nic.backend_uuid)
            client.AddInstanceTags(vm.backend_vm_id, [tag_with_name],
                                   dry_run=settings.TEST)

        # XXX NOP ModifyInstance call to force process_net_status to run
        # on the dispatcher
        os_name = settings.GANETI_CREATEINSTANCE_KWARGS['os']
        client.ModifyInstance(vm.backend_vm_id,
                              os_name=os_name)
开发者ID:cstavr,项目名称:synnefo,代码行数:34,代码来源:backend.py

示例8: update_db

def update_db(vm, msg, event_time):
    """Process a notification of type 'ganeti-op-status'"""
    log.debug("Processing ganeti-op-status msg: %s", msg)

    if msg['type'] != "ganeti-op-status":
        log.error("Message is of unknown type %s.", msg['type'])
        return

    operation = msg["operation"]
    status = msg["status"]
    jobID = msg["jobId"]
    logmsg = msg["logmsg"]
    nics = msg.get("instance_nics", None)
    disks = msg.get("instance_disks", None)
    job_fields = msg.get("job_fields", {})
    result = msg.get("result", [])

    # Special case: OP_INSTANCE_CREATE with opportunistic locking may fail
    # if all Ganeti nodes are already locked. Retry the job without
    # opportunistic locking..
    if (operation == "OP_INSTANCE_CREATE" and status == "error" and
       job_fields.get("opportunistic_locking", False)):
        try:
            error_code = result[1][1]
        except IndexError:
            error_code = None
        if error_code == rapi.ECODE_TEMP_NORES:
            if vm.backendjobid != jobID:  # The job has already been retried!
                return
            # Remove extra fields
            [job_fields.pop(f, None) for f in ("OP_ID", "reason")]
            # Remove 'pnode' and 'snode' if they were set by Ganeti iallocator.
            # Ganeti will fail if both allocator and nodes are specified.
            allocator = job_fields.pop("iallocator", None)
            if allocator is not None:
                [job_fields.pop(f, None) for f in ("pnode", "snode")]
            name = job_fields.pop("name",
                                  job_fields.pop("instance_name", None))
            # Turn off opportunistic locking before retrying the job
            job_fields["opportunistic_locking"] = False
            with pooled_rapi_client(vm) as c:
                jobID = c.CreateInstance(name=name, **job_fields)
            # Update the VM fields
            vm.backendjobid = jobID
            # Update the task_job_id for commissions
            vm.task_job_id = jobID
            vm.backendjobstatus = None
            vm.save()
            log.info("Retrying failed creation of instance '%s' without"
                     " opportunistic locking. New job ID: '%s'", name, jobID)
            return

    backend_mod.process_op_status(vm, event_time, jobID,
                                  operation, status,
                                  logmsg, nics=nics,
                                  disks=disks,
                                  job_fields=job_fields)

    log.debug("Done processing ganeti-op-status msg for vm %s.",
              msg['instance'])
开发者ID:AthinaB,项目名称:synnefo,代码行数:60,代码来源:callbacks.py

示例9: connect_to_network

def connect_to_network(vm, nic):
    backend = vm.backend
    network = nic.network
    address = nic.ipv4
    network = Network.objects.select_for_update().get(id=network.id)
    bnet, created = BackendNetwork.objects.get_or_create(backend=backend,
                                                         network=network)
    depend_jobs = []
    if bnet.operstate != "ACTIVE":
        depend_jobs = create_network(network, backend, connect=True)

    depends = [[job, ["success", "error", "canceled"]] for job in depend_jobs]

    nic = {'ip': address,
           'network': network.backend_id,
           'name': nic.backend_uuid}

    log.debug("Connecting vm %s to network %s(%s)", vm, network, address)

    kwargs = {
        "nics": [('add',  "-1", nic)],
        "depends": depends,
        "dry_run": settings.TEST

    }
    if vm.backend.use_hotplug():
        kwargs["hotplug_if_possible"] = True

    with pooled_rapi_client(vm) as client:
        return client.ModifyInstance(vm.backend_vm_id, **kwargs)
开发者ID:cstavr,项目名称:synnefo,代码行数:30,代码来源:backend.py

示例10: job_is_still_running

def job_is_still_running(vm):
    with pooled_rapi_client(vm) as c:
        try:
            job_info = c.GetJobStatus(vm.backendjobid)
            return not (job_info["status"] in JOB_STATUS_FINALIZED)
        except GanetiApiError:
            return False
开发者ID:cstavr,项目名称:synnefo,代码行数:7,代码来源:backend.py

示例11: create_instance

def create_instance(vm, public_nic, flavor, image):
    """`image` is a dictionary which should contain the keys:
            'backend_id', 'format' and 'metadata'

        metadata value should be a dictionary.
    """

    # Handle arguments to CreateInstance() as a dictionary,
    # initialize it based on a deployment-specific value.
    # This enables the administrator to override deployment-specific
    # arguments, such as the disk template to use, name of os provider
    # and hypervisor-specific parameters at will (see Synnefo #785, #835).
    #
    kw = vm.backend.get_create_params()
    kw['mode'] = 'create'
    kw['name'] = vm.backend_vm_id
    # Defined in settings.GANETI_CREATEINSTANCE_KWARGS

    kw['disk_template'] = flavor.disk_template
    kw['disks'] = [{"size": flavor.disk * 1024}]
    provider = flavor.disk_provider
    if provider:
        kw['disks'][0]['provider'] = provider
        kw['disks'][0]['origin'] = flavor.disk_origin

    kw['nics'] = [{"name": public_nic.backend_uuid,
                  "network": public_nic.network.backend_id,
                  "ip": public_nic.ipv4}]
    # Defined in settings.GANETI_CREATEINSTANCE_KWARGS
    # kw['os'] = settings.GANETI_OS_PROVIDER
    kw['ip_check'] = False
    kw['name_check'] = False

    # Do not specific a node explicitly, have
    # Ganeti use an iallocator instead
    #kw['pnode'] = rapi.GetNodes()[0]

    kw['dry_run'] = settings.TEST

    kw['beparams'] = {
        'auto_balance': True,
        'vcpus': flavor.cpu,
        'memory': flavor.ram}

    kw['osparams'] = {
        'config_url': vm.config_url,
        # Store image id and format to Ganeti
        'img_id': image['backend_id'],
        'img_format': image['format']}

    # Use opportunistic locking
    kw['opportunistic_locking'] = settings.GANETI_USE_OPPORTUNISTIC_LOCKING

    # Defined in settings.GANETI_CREATEINSTANCE_KWARGS
    # kw['hvparams'] = dict(serial_console=False)

    log.debug("Creating instance %s", utils.hide_pass(kw))
    with pooled_rapi_client(vm) as client:
        return client.CreateInstance(**kw)
开发者ID:cstavr,项目名称:synnefo,代码行数:59,代码来源:backend.py

示例12: disconnect_from_network

def disconnect_from_network(vm, nic):
    op = [('remove', nic.index, {})]

    log.debug("Removing nic of VM %s, with index %s", vm, str(nic.index))

    with pooled_rapi_client(vm) as client:
        return client.ModifyInstance(vm.backend_vm_id, nics=op,
                                     hotplug=vm.backend.use_hotplug(),
                                     dry_run=settings.TEST)
开发者ID:mpastyl,项目名称:websocket-console,代码行数:9,代码来源:backend.py

示例13: job_is_still_running

def job_is_still_running(vm, job_id=None):
    with pooled_rapi_client(vm) as c:
        try:
            if job_id is None:
                job_id = vm.backendjobid
            job_info = c.GetJobStatus(job_id)
            return not (job_info["status"] in rapi.JOB_STATUS_FINALIZED)
        except rapi.GanetiApiError:
            return False
开发者ID:apyrgio,项目名称:synnefo,代码行数:9,代码来源:backend.py

示例14: connect_network_synced

def connect_network_synced(network, backend):
    with pooled_rapi_client(backend) as client:
        for group in client.GetGroups():
            job = client.ConnectNetwork(network.backend_id, group,
                                        network.mode, network.link)
            result = wait_for_job(client, job)
            if result[0] != rapi.JOB_STATUS_SUCCESS:
                return result

    return result
开发者ID:apyrgio,项目名称:synnefo,代码行数:10,代码来源:backend.py

示例15: disconnect_network

def disconnect_network(network, backend, group=None):
    log.debug("Disconnecting network %s to backend %s", network, backend)

    with pooled_rapi_client(backend) as client:
        groups = [group] if group is not None else client.GetGroups()
        job_ids = []
        for group in groups:
            job_id = client.DisconnectNetwork(network.backend_id, group)
            job_ids.append(job_id)
    return job_ids
开发者ID:apyrgio,项目名称:synnefo,代码行数:10,代码来源:backend.py


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