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
def get_provider_key(cls, cloud_prop): """ Return a cloud Provider object for the given cloud properties. """ profile_file = cloud_prop.get("profile") if not profile_file: raise CloudError( "required node property 'cloud.profile' pointing to a profile file not defined" ) return ("PONILV", profile_file)
def __init__(self, msg, code=None): CloudError.__init__(self, msg) self.code = code