Ejemplo n.º 1
0
    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") }
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
 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"))
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 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))
Ejemplo n.º 7
0
    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")}
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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")
Ejemplo n.º 10
0
 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
Ejemplo n.º 11
0
 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
     self._target_host = xml.find("attrs/attr[@name='targetHost']/string").get("value")
Ejemplo n.º 12
0
 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")
Ejemplo n.º 13
0
 def __init__(self, xml):
     MachineDefinition.__init__(self, xml)
     x = xml.find("attrs/attr[@name='container']/attrs")
     assert x is not None
     self.host = x.find("attr[@name='host']/string").get("value")
Ejemplo n.º 14
0
    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)
        self.copy_option(x, 'subnet', str, 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))
Ejemplo n.º 15
0
 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"]
Ejemplo n.º 16
0
Archivo: none.py Proyecto: NixOS/nixops
    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")
Ejemplo n.º 17
0
 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"]
Ejemplo n.º 18
0
 def __init__(self, xml, config):
     MachineDefinition.__init__(self, xml, config)
Ejemplo n.º 19
0
 def __init__(self, xml):
     MachineDefinition.__init__(self, xml)
     self._target_host = xml.find(
         "attrs/attr[@name='targetHost']/string").get("value")