Exemple #1
0
    def __init__(self, cloud_prop):
        if MISSING_LIBS:
            raise CloudError("missing libraries required by libvirt deployment: " + ", ".join(MISSING_LIBS))

        Provider.__init__(self, "libvirt", cloud_prop)
        self.log = logging.getLogger("poni.libvirt")
        self.ssh_key = None
        profile_file = cloud_prop.get("profile")
        if not profile_file:
            raise CloudError("required node property 'cloud.profile' pointing to a profile file not defined")

        profile = json.load(open(profile_file, "rb"))
        if "ssh_key" in profile:
            self.ssh_key = os.path.expandvars(os.path.expanduser(profile["ssh_key"]))

        # Look up all hypervisor hosts, they can be defined one-by-one
        # ("nodes" property) in which case we use the highest priorities
        # with them.  They can also be defined in SRV records in "services"
        # property as well as an older style "nodesets" property without
        # service information in which case we use _libvirt._tcp.
        if not DNS.defaults["server"]:
            DNS.DiscoverNameServers()
        hosts = {}
        for entry in profile.get("nodes", []):
            host, _, port = entry.partition(":")
            hosts["{0}:{1}".format(host, port or 22)] = (0, 100)
        services = set(profile.get("services", []))
        services.update("_libvirt._tcp.{0}".format(host) for host in profile.get("nodesets", []))
        for entry in services:
            for priority, weight, port, host in _lv_dns_lookup(entry, "SRV"):
                hosts["{0}:{1}".format(host, port)] = (priority, weight)
        self.hosts = hosts
        self.hosts_online = None
Exemple #2
0
    def __init__(self, cloud_prop):
        if MISSING_LIBS:
            raise CloudError("missing libraries required by libvirt deployment: %s" % (", ".join(MISSING_LIBS)))

        Provider.__init__(self, 'libvirt', cloud_prop)
        self.log = logging.getLogger("poni.libvirt")
        self.ssh_key = None
        profile = json.load(open(cloud_prop["profile"], "rb"))
        if "ssh_key" in profile:
            self.ssh_key = os.path.expandvars(os.path.expanduser(profile["ssh_key"]))

        # Look up all hypervisor hosts, they can be defined one-by-one
        # ("nodes" property) in which case we use the highest priorities
        # with them.  They can also be defined in SRV records in "services"
        # property as well as an older style "nodesets" property without
        # service information in which case we use _libvirt._tcp.
        if not DNS.defaults["server"]:
            DNS.DiscoverNameServers()
        hosts = {}
        for entry in profile.get("nodes", []):
            host, _, port = entry.partition(":")
            hosts["{0}:{1}".format(host, port or 22)] = (0, 100)
        services = set(profile.get("services", []))
        services.update("_libvirt._tcp.{0}".format(host) for host in profile.get("nodesets", []))
        for entry in services:
            for priority, weight, port, host in _lv_dns_lookup(entry, "SRV"):
                hosts["{0}:{1}".format(host, port)] = (priority, weight)
        self.hosts = hosts
        self.hosts_online = None
Exemple #3
0
    def __init__(self, cloud_prop):
        if MISSING_LIBS:
            raise CloudError("missing libraries required by libvirt deployment: " + ", ".join(MISSING_LIBS))

        Provider.__init__(self, "libvirt", cloud_prop)
        self.log = logging.getLogger("poni.libvirt")

        # Use a json profile file if one is defined, otherwise use
        # properties directly from `cloud_prop`
        profile_file = cloud_prop.get("profile")
        if profile_file:
            profile = json.load(open(profile_file, "rb"))
        else:
            profile = cloud_prop

        self.hypervisor = profile.get("hypervisor", "kvm")
        if "ssh_key" in profile:
            self.ssh_key = os.path.expandvars(os.path.expanduser(profile["ssh_key"]))
        else:
            self.ssh_key = None

        # default to accessing the hosts as root unless something else is
        # specified or caller asks not to pass username by setting it empty
        user = profile.get("username", "root")
        user_at = user + "@" if user else ""

        # Look up all hypervisor hosts, they can be defined one-by-one
        # ("nodes" property) in which case we use the highest priorities
        # with them.  They can also be defined in SRV records in "services"
        # property as well as an older style "nodesets" property without
        # service information in which case we use _libvirt._tcp.
        hosts = {}
        for entry in profile.get("nodes", []):
            hosts[user_at + entry] = (0, 100)
        services = set(profile.get("services", []))
        services.update("_libvirt._tcp.{0}".format(host) for host in profile.get("nodesets", []))
        for entry in services:
            for priority, weight, port, host in _lv_dns_lookup(entry):
                hosts["{0}{1}:{2}".format(user_at, host, port)] = (priority, weight)
        self.hosts = hosts
        self.hosts_online = None