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

Python backends.MachineDefinition类代码示例

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

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



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

示例1: __init__

    def __init__(self, xml, config):
        MachineDefinition.__init__(self, xml, config)

        x = xml.find("attrs/attr[@name='libvirtd']/attrs")
        assert x is not None
        self.vcpu = x.find("attr[@name='vcpu']/int").get("value")
        self.memory_size = x.find("attr[@name='memorySize']/int").get("value")
        self.extra_devices = x.find("attr[@name='extraDevicesXML']/string").get("value")
        self.extra_domain = x.find("attr[@name='extraDomainXML']/string").get("value")
        self.headless = x.find("attr[@name='headless']/bool").get("value") == 'true'
        self.image_dir = x.find("attr[@name='imageDir']/string").get("value")
        assert self.image_dir is not None

        self.networks = [
            k.get("value")
            for k in x.findall("attr[@name='networks']/list/string")]
        assert len(self.networks) > 0

        def parse_disk(xml):
            result = {
                'device': xml.find("attrs/attr[@name='device']/string").get("value"),
                'size': xml.find("attrs/attr[@name='size']/int").get("value"),
            }
            baseImageDefn = xml.find("attrs/attr[@name='baseImage']/string")
            if baseImageDefn is not None:
                result.baseImage = baseImageDefn.get("value")
            return result

        self.disks = { k.get("name"): parse_disk(k)
                       for k in x.findall("attr[@name='disks']/attrs/attr") }
开发者ID:coreyoconnor,项目名称:nixops,代码行数:30,代码来源:libvirtd.py


示例2: __init__

    def __init__(self, xml, config):
        MachineDefinition.__init__(self, xml, config)
        x = xml.find("attrs/attr[@name='gce']/attrs")
        assert x is not None
        self.copy_option(x, 'machineName', str)

        self.copy_option(x, 'region', str)
        self.copy_option(x, 'instanceType', str, empty = False)
        self.copy_option(x, 'project', str)
        self.copy_option(x, 'serviceAccount', str)
        self.access_key_path = self.get_option_value(x, 'accessKey', str)

        self.copy_option(x, 'tags', 'strlist')
        self.metadata = { k.get("name"): k.find("string").get("value")
                          for k in x.findall("attr[@name='metadata']/attrs/attr") }

        scheduling = x.find("attr[@name='scheduling']")
        self.copy_option(scheduling, 'automaticRestart', bool)
        self.copy_option(scheduling, 'preemptible', bool)
        self.copy_option(scheduling, 'onHostMaintenance', str)

        instance_service_account = x.find("attr[@name='instanceServiceAccount']")
        self.copy_option(instance_service_account, "email", str)
        self.copy_option(instance_service_account, "scopes", 'strlist')

        self.ipAddress = self.get_option_value(x, 'ipAddress', 'resource', optional = True)
        self.copy_option(x, 'network', 'resource', optional = True)

        def opt_disk_name(dname):
            return ("{0}-{1}".format(self.machine_name, dname) if dname is not None else None)

        def parse_block_device(xml):
            result = {
                'disk': self.get_option_value(xml, 'disk', 'resource', optional = True),
                'disk_name': opt_disk_name(self.get_option_value(xml, 'disk_name', str, optional = True)),
                'snapshot': self.get_option_value(xml, 'snapshot', str, optional = True),
                'image': self.get_option_value(xml, 'image', 'resource', optional = True),
                'size': self.get_option_value(xml, 'size', int, optional = True),
                'type': self.get_option_value(xml, 'diskType', str),
                'deleteOnTermination': self.get_option_value(xml, 'deleteOnTermination', bool),
                'readOnly': self.get_option_value(xml, 'readOnly', bool),
                'bootDisk': self.get_option_value(xml, 'bootDisk', bool),
                'encrypt': self.get_option_value(xml, 'encrypt', bool),
                'passphrase': self.get_option_value(xml, 'passphrase', str)
            }
            if not(result['disk'] or result['disk_name']):
                raise Exception("{0}: blockDeviceMapping item must specify either an "
                                "external disk name to mount or a disk name to create"
                                .format(self.machine_name))
            return result

        self.block_device_mapping = { k.get("name"): parse_block_device(k)
                                      for k in x.findall("attr[@name='blockDeviceMapping']/attrs/attr") }

        boot_devices = [k for k,v in self.block_device_mapping.iteritems() if v['bootDisk']]
        if len(boot_devices) == 0:
            raise Exception("machine {0} must have a boot device.".format(self.name))
        if len(boot_devices) > 1:
            raise Exception("machine {0} must have exactly one boot device.".format(self.name))
开发者ID:AmineChikhaoui,项目名称:nixops,代码行数:59,代码来源:gce.py


示例3: __init__

    def __init__(self, xml):
        MachineDefinition.__init__(self, xml)
        x = xml.find("attrs/attr[@name='gce']/attrs")
        assert x is not None

        self.copy_option(x, "machineName", str)

        self.copy_option(x, "region", str)
        self.copy_option(x, "instanceType", str, empty=False)
        self.copy_option(x, "project", str)
        self.copy_option(x, "serviceAccount", str)
        self.access_key_path = self.get_option_value(x, "accessKey", str)

        self.copy_option(x, "tags", "strlist")
        self.metadata = {
            k.get("name"): k.find("string").get("value") for k in x.findall("attr[@name='metadata']/attrs/attr")
        }

        scheduling = x.find("attr[@name='scheduling']")
        self.copy_option(scheduling, "automaticRestart", bool)
        self.copy_option(scheduling, "onHostMaintenance", str)

        self.ipAddress = self.get_option_value(x, "ipAddress", "resource", optional=True)
        self.copy_option(x, "network", "resource", optional=True)

        def opt_disk_name(dname):
            return "{0}-{1}".format(self.machine_name, dname) if dname is not None else None

        def parse_block_device(xml):
            result = {
                "disk": self.get_option_value(xml, "disk", "resource", optional=True),
                "disk_name": opt_disk_name(self.get_option_value(xml, "disk_name", str, optional=True)),
                "snapshot": self.get_option_value(xml, "snapshot", str, optional=True),
                "image": self.get_option_value(xml, "image", "resource", optional=True),
                "size": self.get_option_value(xml, "size", int, optional=True),
                "type": self.get_option_value(xml, "diskType", str),
                "deleteOnTermination": self.get_option_value(xml, "deleteOnTermination", bool),
                "readOnly": self.get_option_value(xml, "readOnly", bool),
                "bootDisk": self.get_option_value(xml, "bootDisk", bool),
                "encrypt": self.get_option_value(xml, "encrypt", bool),
                "passphrase": self.get_option_value(xml, "passphrase", str),
            }
            if not (result["disk"] or result["disk_name"]):
                raise Exception(
                    "{0}: blockDeviceMapping item must specify either an "
                    "external disk name to mount or a disk name to create".format(self.machine_name)
                )
            return result

        self.block_device_mapping = {
            k.get("name"): parse_block_device(k) for k in x.findall("attr[@name='blockDeviceMapping']/attrs/attr")
        }

        boot_devices = [k for k, v in self.block_device_mapping.iteritems() if v["bootDisk"]]
        if len(boot_devices) == 0:
            raise Exception("machine {0} must have a boot device.".format(self.name))
        if len(boot_devices) > 1:
            raise Exception("machine {0} must have exactly one boot device.".format(self.name))
开发者ID:thedebugger,项目名称:nixops,代码行数:58,代码来源:gce.py


示例4: __init__

 def __init__(self, xml):
     MachineDefinition.__init__(self, xml)
     x = xml.find("attrs/attr[@name='hetzner']/attrs")
     assert x is not None
     for var, name, valtype in [("main_ipv4", "mainIPv4", "string"),
                                ("robot_user", "robotUser", "string"),
                                ("robot_pass", "robotPass", "string"),
                                ("partitions", "partitions", "string")]:
         attr = x.find("attr[@name='" + name + "']/" + valtype)
         setattr(self, var, attr.get("value"))
开发者ID:pombredanne,项目名称:nixops,代码行数:10,代码来源:hetzner.py


示例5: __init__

    def __init__(self, xml):
        MachineDefinition.__init__(self, xml)

        x = xml.find("attrs/attr[@name='libvirtd']/attrs")
        assert x is not None
        self.memory_size = x.find("attr[@name='memorySize']/int").get("value")
        self.image_dir = x.find("attr[@name='imageDir']/string").get("value")
        assert self.image_dir is not None

        self.networks = [ k.find("string").get("value")
                            for k in x.findall("attr[@name='networks']/list") ]
        assert len(self.networks) > 0
开发者ID:Bsami,项目名称:nixops,代码行数:12,代码来源:libvirtd.py


示例6: __init__

 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
     x = xml.find("attrs/attr[@name='hetzner']/attrs")
     assert x is not None
     attrs = [("main_ipv4", "mainIPv4", "string"),
              ("create_sub_account", "createSubAccount", "bool"),
              ("robot_user", "robotUser", "string"),
              ("robot_pass", "robotPass", "string"),
              ("partitions", "partitions", "string")]
     for var, name, valtype in attrs:
         node = x.find("attr[@name='" + name + "']/" + valtype)
         setattr(self, var, xml_expr_to_python(node))
开发者ID:NixOS,项目名称:nixops,代码行数:12,代码来源:hetzner.py


示例7: __init__

    def __init__(self, xml):
        MachineDefinition.__init__(self, xml)
        x = xml.find("attrs/attr[@name='virtualbox']/attrs")
        assert x is not None
        self.memory_size = x.find("attr[@name='memorySize']/int").get("value")
        self.headless = x.find("attr[@name='headless']/bool").get("value") == "true"

        def f(xml):
            return {'port': int(xml.find("attrs/attr[@name='port']/int").get("value")),
                    'size': int(xml.find("attrs/attr[@name='size']/int").get("value")),
                    'baseImage': xml.find("attrs/attr[@name='baseImage']/string").get("value")}

        self.disks = {k.get("name"): f(k) for k in x.findall("attr[@name='disks']/attrs/attr")}
开发者ID:offlinehacker,项目名称:nixops,代码行数:13,代码来源:virtualbox.py


示例8: __init__

    def __init__(self, xml, config):
        MachineDefinition.__init__(self, xml, config)

        x = xml.find("attrs/attr[@name='libvirtd']/attrs")
        assert x is not None
        self.memory_size = x.find("attr[@name='memorySize']/int").get("value")
        self.extra_devices = x.find("attr[@name='extraDevicesXML']/string").get("value")
        self.headless = x.find("attr[@name='headless']/bool").get("value") == 'true'
        self.image_dir = x.find("attr[@name='imageDir']/string").get("value")
        assert self.image_dir is not None

        self.networks = [
            k.get("value")
            for k in x.findall("attr[@name='networks']/list/string")]
        assert len(self.networks) > 0
开发者ID:aycanirican,项目名称:nixops,代码行数:15,代码来源:libvirtd.py


示例9: __init__

    def __init__(self, xml):
        MachineDefinition.__init__(self, xml)
        x = xml.find("attrs/attr[@name='ec2']/attrs")
        assert x is not None
        self.access_key_id = x.find("attr[@name='accessKeyId']/string").get("value")
        self.type = x.find("attr[@name='type']/string").get("value")
        self.region = x.find("attr[@name='region']/string").get("value")
        self.zone = x.find("attr[@name='zone']/string").get("value")
        self.controller = x.find("attr[@name='controller']/string").get("value")
        self.ami = x.find("attr[@name='ami']/string").get("value")
        if self.ami == "":
            raise Exception("no AMI defined for EC2 machine ‘{0}’".format(self.name))
        self.instance_type = x.find("attr[@name='instanceType']/string").get("value")
        self.key_pair = x.find("attr[@name='keyPair']/string").get("value")
        self.private_key = x.find("attr[@name='privateKey']/string").get("value")
        self.security_groups = [e.get("value") for e in x.findall("attr[@name='securityGroups']/list/string")]
        self.instance_profile = x.find("attr[@name='instanceProfile']/string").get("value")
        self.tags = {k.get("name"): k.find("string").get("value") for k in x.findall("attr[@name='tags']/attrs/attr")}
        self.root_disk_size = int(x.find("attr[@name='ebsInitialRootDiskSize']/int").get("value"))
        self.spot_instance_price = int(x.find("attr[@name='spotInstancePrice']/int").get("value"))

        def f(xml):
            return {'disk': xml.find("attrs/attr[@name='disk']/string").get("value"),
                    'size': int(xml.find("attrs/attr[@name='size']/int").get("value")),
                    'iops': int(xml.find("attrs/attr[@name='iops']/int").get("value")),
                    'fsType': xml.find("attrs/attr[@name='fsType']/string").get("value"),
                    'deleteOnTermination': xml.find("attrs/attr[@name='deleteOnTermination']/bool").get("value") == "true",
                    'encrypt': xml.find("attrs/attr[@name='encrypt']/bool").get("value") == "true",
                    'passphrase': xml.find("attrs/attr[@name='passphrase']/string").get("value")}

        self.block_device_mapping = {_xvd_to_sd(k.get("name")): f(k) for k in x.findall("attr[@name='blockDeviceMapping']/attrs/attr")}
        self.elastic_ipv4 = x.find("attr[@name='elasticIPv4']/string").get("value")

        x = xml.find("attrs/attr[@name='route53']/attrs")
        assert x is not None
        self.dns_hostname = x.find("attr[@name='hostName']/string").get("value")
        self.dns_ttl = x.find("attr[@name='ttl']/int").get("value")
        self.route53_access_key_id = x.find("attr[@name='accessKeyId']/string").get("value")
开发者ID:wizeman,项目名称:nixops,代码行数:38,代码来源:ec2.py


示例10: __init__

 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
开发者ID:MostAwesomeDude,项目名称:nixops,代码行数:2,代码来源:virtualbox.py


示例11: __init__

 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
     x = xml.find("attrs/attr[@name='container']/attrs")
     assert x is not None
     self.host = x.find("attr[@name='host']/string").get("value")
开发者ID:coreyoconnor,项目名称:nixops,代码行数:5,代码来源:container.py


示例12: __init__

 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
     self._target_host = xml.find("attrs/attr[@name='targetHost']/string").get("value")
开发者ID:Acidburn0zzz,项目名称:nixops,代码行数:3,代码来源:none.py


示例13: __init__

 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
     self.auth_token = config["digitalOcean"]["authToken"]
     self.region = config["digitalOcean"]["region"]
     self.size = config["digitalOcean"]["size"]
     self.enable_ipv6 = config["digitalOcean"]["enableIpv6"]
开发者ID:MostAwesomeDude,项目名称:nixops,代码行数:6,代码来源:digital_ocean.py


示例14: __init__

    def __init__(self, xml, config):
        MachineDefinition.__init__(self, xml, config)
        self._target_host = xml.find("attrs/attr[@name='targetHost']/string").get("value")

        public_ipv4 = xml.find("attrs/attr[@name='publicIPv4']/string")
        self._public_ipv4 = None if public_ipv4 is None else public_ipv4.get("value")
开发者ID:NixOS,项目名称:nixops,代码行数:6,代码来源:none.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python backends.MachineState类代码示例发布时间:2022-05-27
下一篇:
Python i18n._函数代码示例发布时间: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