• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python nova.client函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _shutdown_instance

    def _shutdown_instance(self, instance):
        ctx = context.ctx()

        if instance.node_group.floating_ip_pool:
            try:
                networks.delete_floating_ip(instance.instance_id)
            except nova_exceptions.NotFound:
                LOG.warn("Attempted to delete non-existent floating IP in "
                         "pool %s from instancie %s",
                         instance.node_group.floating_ip_pool,
                         instance.instance_id)

        try:
            volumes.detach_from_instance(instance)
        except Exception:
            LOG.warn("Detaching volumes from instance %s failed",
                     instance.instance_id)

        try:
            nova.client().servers.delete(instance.instance_id)
        except nova_exceptions.NotFound:
            LOG.warn("Attempted to delete non-existent instance %s",
                     instance.instance_id)

        conductor.instance_remove(ctx, instance)
开发者ID:hguemar,项目名称:sahara,代码行数:25,代码来源:direct_engine.py


示例2: delete_floating_ip

def delete_floating_ip(instance_id):
    fl_ips = nova.client().floating_ips.findall(instance_id=instance_id)
    for fl_ip in fl_ips:
        if CONF.use_neutron:
            nova.client().floating_ips.delete(fl_ip.id)
        else:
            nova.client().floating_ips.delete(fl_ip.ip)
开发者ID:chiehwen,项目名称:savanna,代码行数:7,代码来源:networks.py


示例3: _shutdown_instance

def _shutdown_instance(instance):
    ctx = context.ctx()
    try:
        nova.client().servers.delete(instance.instance_id)
    except nova_exceptions.NotFound:
        #Just ignore non-existing instances
        pass

    conductor.instance_remove(ctx, instance)
开发者ID:StokesB1,项目名称:savanna,代码行数:9,代码来源:instances.py


示例4: _shutdown_instance

def _shutdown_instance(instance):
    session = context.ctx().session
    try:
        nova.client().servers.delete(instance.instance_id)
    except nova_exceptions.NotFound:
        #Just ignore non-existing instances
        pass

    with session.begin():
        session.delete(instance)
开发者ID:akshayms,项目名称:savanna,代码行数:10,代码来源:instances.py


示例5: _shutdown_instance

def _shutdown_instance(instance):
    ctx = context.ctx()
    try:
        if instance.node_group.floating_ip_pool:
            networks.delete_floating_ip(instance.instance_id)
        nova.client().servers.delete(instance.instance_id)
    except nova_exceptions.NotFound:
        #Just ignore non-existing instances
        pass

    conductor.instance_remove(ctx, instance)
开发者ID:chiehwen,项目名称:savanna,代码行数:11,代码来源:instances.py


示例6: _rollback_cluster_creation

def _rollback_cluster_creation(cluster, ex):
    """Shutdown all instances and update cluster status."""
    LOG.info("Cluster '%s' creation rollback (reason: %s)", cluster.name, ex)

    session = context.ctx().session
    _shutdown_instances(cluster, True)
    volumes.detach(cluster)
    alive_instances = set([srv.id for srv in nova.client().servers.list()])

    for node_group in cluster.node_groups:
        for instance in node_group.instances:
            if instance.instance_id in alive_instances:
                nova.client().servers.delete(instance.instance_id)
            with session.begin():
                session.delete(instance)
开发者ID:akshayms,项目名称:savanna,代码行数:15,代码来源:instances.py


示例7: init_instances_ips

def init_instances_ips(instance, server):
    """Extracts internal and management ips.

    As internal ip will be used the first ip from the nova networks CIDRs.
    If use_floating_ip flag is set than management ip will be the first
    non-internal ip.
    """
    ctx = context.ctx()

    if instance.internal_ip and instance.management_ip:
        return True

    management_ip = instance.management_ip
    internal_ip = instance.internal_ip

    for network_label in server.networks:
        nova_network = nova.client().networks.find(label=network_label)
        network = netaddr.IPNetwork(nova_network.cidr)
        for ip in server.networks[network_label]:
            if netaddr.IPAddress(ip) in network:
                internal_ip = instance.internal_ip or ip
            else:
                management_ip = instance.management_ip or ip

    if not CONF.use_floating_ips:
        management_ip = internal_ip

    conductor.instance_update(ctx, instance, {"management_ip": management_ip,
                                              "internal_ip": internal_ip})

    return internal_ip and management_ip
开发者ID:jfzhang2013,项目名称:savanna,代码行数:31,代码来源:networks.py


示例8: _create_attach_volume

def _create_attach_volume(instance, size, device_path, display_name=None,
                          volume_type=None):
    volume = cinder.client().volumes.create(size=size,
                                            display_name=display_name,
                                            volume_type=volume_type)
    instance.volumes.append(volume.id)

    while volume.status != 'available':
        volume = cinder.get_volume(volume.id)
        if volume.status == 'error':
            raise RuntimeError("Volume %s has error status" % volume.id)

        context.sleep(1)

    nova.client().volumes.create_server_volume(instance.instance_id,
                                               volume.id, device_path)
开发者ID:jfzhang1984,项目名称:savanna,代码行数:16,代码来源:volumes.py


示例9: _run_instance

def _run_instance(cluster, node_group, idx, aa_groups, userdata):
    """Create instance using nova client and persist them into DB."""
    session = context.ctx().session
    name = '%s-%s-%03d' % (cluster.name, node_group.name, idx)

    # aa_groups: node process -> instance ids
    aa_ids = []
    for node_process in node_group.node_processes:
        aa_ids += aa_groups.get(node_process) or []

    # create instances only at hosts w/ no instances w/ aa-enabled processes
    hints = {'different_host': list(set(aa_ids))} if aa_ids else None

    context.model_save(node_group)

    nova_instance = nova.client().servers.create(
        name, node_group.get_image_id(), node_group.flavor_id,
        scheduler_hints=hints, userdata=userdata,
        key_name=cluster.user_keypair_id)

    with session.begin():
        instance = m.Instance(node_group.id, nova_instance.id, name)
        node_group.instances.append(instance)
        session.add(instance)

    # save instance id to aa_groups to support aa feature
    for node_process in node_group.node_processes:
        if node_process in cluster.anti_affinity:
            aa_group_ids = aa_groups.get(node_process, [])
            aa_group_ids.append(nova_instance.id)
            aa_groups[node_process] = aa_group_ids

    return instance
开发者ID:akshayms,项目名称:savanna,代码行数:33,代码来源:instances.py


示例10: user_keypair

    def user_keypair(self):
        """Extract user keypair object from nova.

        It contains 'public_key' and 'fingerprint' fields.
        """
        if not hasattr(self, '_user_kp'):
            try:
                self._user_kp = nova.client().keypairs.get(
                    self.user_keypair_id)
            except nova_ex.NotFound:
                self._user_kp = None
        return self._user_kp
开发者ID:zuiwanyuan,项目名称:savanna,代码行数:12,代码来源:models.py


示例11: _run_instance

    def _run_instance(self, cluster, node_group, idx, aa_groups, userdata):
        """Create instance using nova client and persist them into DB."""
        ctx = context.ctx()
        name = '%s-%s-%03d' % (cluster.name, node_group.name, idx)

        # aa_groups: node process -> instance ids
        aa_ids = []
        for node_process in node_group.node_processes:
            aa_ids += aa_groups.get(node_process) or []

        # create instances only at hosts w/ no instances
        # w/ aa-enabled processes
        hints = {'different_host': list(set(aa_ids))} if aa_ids else None

        if CONF.use_neutron:
            net_id = cluster.neutron_management_network
            nics = [{"net-id": net_id, "v4-fixed-ip": ""}]

            nova_instance = nova.client().servers.create(
                name, node_group.get_image_id(), node_group.flavor_id,
                scheduler_hints=hints, userdata=userdata,
                key_name=cluster.user_keypair_id,
                nics=nics)
        else:
            nova_instance = nova.client().servers.create(
                name, node_group.get_image_id(), node_group.flavor_id,
                scheduler_hints=hints, userdata=userdata,
                key_name=cluster.user_keypair_id)

        instance_id = conductor.instance_add(ctx, node_group,
                                             {"instance_id": nova_instance.id,
                                              "instance_name": name})
        # save instance id to aa_groups to support aa feature
        for node_process in node_group.node_processes:
            if node_process in cluster.anti_affinity:
                aa_group_ids = aa_groups.get(node_process, [])
                aa_group_ids.append(nova_instance.id)
                aa_groups[node_process] = aa_group_ids

        return instance_id
开发者ID:hguemar,项目名称:sahara,代码行数:40,代码来源:direct_engine.py


示例12: init_neutron_ips

def init_neutron_ips(instance, server):
    ctx = context.ctx()

    net_id = instance.node_group.cluster.neutron_management_network
    net_name = nova.client().networks.get(net_id).label

    internal_ip = server.networks.get(net_name, [None])[0]
    management_ip = internal_ip

    conductor.instance_update(ctx, instance, {"management_ip": management_ip,
                                              "internal_ip": internal_ip})

    return internal_ip
开发者ID:StokesB1,项目名称:savanna,代码行数:13,代码来源:networks.py


示例13: generate_topology_map

def generate_topology_map(cluster, is_node_awareness):
    mapping = _read_compute_topology()
    nova_client = nova.client()
    topology_mapping = {}
    for ng in cluster.node_groups:
        for i in ng.instances:
            #TODO(alazarev) get all servers info with one request
            ni = nova_client.servers.get(i.instance_id)
            hostId = ni.hostId
            if hostId not in mapping:
                raise ex.NotFoundException(
                    i.instance_id, "Was not able to find compute node "
                                   "topology for VM %s")
            rack = mapping[hostId]
            if is_node_awareness:
                rack += "/" + hostId

            topology_mapping[i.instance_name] = rack
            topology_mapping[i.management_ip] = rack
            topology_mapping[i.internal_ip] = rack

    topology_mapping.update(_read_swift_topology())

    return topology_mapping
开发者ID:joelmathew,项目名称:savanna,代码行数:24,代码来源:topology_helper.py


示例14: remove_image_tags

def remove_image_tags(image_id, tags):
    client = nova.client()
    client.images.untag(image_id, tags)
    return client.images.get(image_id)
开发者ID:joelmathew,项目名称:savanna,代码行数:4,代码来源:api.py


示例15: add_image_tags

def add_image_tags(image_id, tags):
    client = nova.client()
    client.images.tag(image_id, tags)
    return client.images.get(image_id)
开发者ID:joelmathew,项目名称:savanna,代码行数:4,代码来源:api.py


示例16: unregister_image

def unregister_image(image_id):
    client = nova.client()
    client.images.unset_description(image_id)
    return client.images.get(image_id)
开发者ID:joelmathew,项目名称:savanna,代码行数:4,代码来源:api.py


示例17: register_image

def register_image(image_id, username, description=None):
    client = nova.client()
    client.images.set_description(image_id, username, description)
    return client.images.get(image_id)
开发者ID:joelmathew,项目名称:savanna,代码行数:4,代码来源:api.py


示例18: get_image

def get_image(**kwargs):
    if len(kwargs) == 1 and 'id' in kwargs:
        return nova.client().images.get(kwargs['id'])
    else:
        return nova.client().images.find(**kwargs)
开发者ID:joelmathew,项目名称:savanna,代码行数:5,代码来源:api.py


示例19: get_images

def get_images(tags):
    return nova.client().images.list_registered(tags)
开发者ID:joelmathew,项目名称:savanna,代码行数:2,代码来源:api.py


示例20: delete_floating_ip

def delete_floating_ip(instance_id):
    fl_ips = nova.client().floating_ips.findall(instance_id=instance_id)
    for fl_ip in fl_ips:
        nova.client().floating_ips.delete(fl_ip.id)
开发者ID:hguemar,项目名称:sahara,代码行数:4,代码来源:networks.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python remote.get_remote函数代码示例发布时间:2022-05-27
下一篇:
Python api.render函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap