def local_templates(self, template): templates = {} for mxn_file in self._absolute_file_paths(self.rocci_template_dir): mxn = self._read_mixin(mxn_file) occi_attrs = self._traverse(mxn, 'attributes', 'occi', 'compute') if not occi_attrs: msg = 'Failed to get compute attributes' \ ' for mixin in %s' % (mxn_file) raise exceptions.OpenNebulaProviderException(msg) flid = '%s#%s' % (mxn['scheme'].rstrip('#'), mxn['term']) cores = self._traverse(occi_attrs, 'cores', 'Default') or 0 memory = self._traverse(occi_attrs, 'memory', 'Default') or 0 disk = self._traverse( occi_attrs, 'ephemeral_storage', 'size', 'Default') or 0 aux = template.copy() aux.update({ 'template_id': flid, 'template_cpu': cores, 'template_memory': int(memory * 1024), 'template_description': mxn['title'], 'template_disk': disk, }) templates[aux['template_id']] = aux return templates
def local_templates(self, template): templates = {} for mxn_file in self._absolute_file_paths(self.rocci_template_dir): mxn = self._read_mixin(mxn_file) occi_attrs = self._traverse(mxn, "attributes", "occi", "compute") if not occi_attrs: msg = "Failed to get compute attributes" " for mixin in %s" % ( mxn_file) raise exceptions.OpenNebulaProviderException(msg) flid = "%s#%s" % (mxn["scheme"].rstrip("#"), mxn["term"]) cores = self._traverse(occi_attrs, "cores", "Default") or 0 memory = self._traverse(occi_attrs, "memory", "Default") or 0 disk = (self._traverse(occi_attrs, "ephemeral_storage", "size", "Default") or 0) aux = template.copy() aux.update({ "template_id": flid, "template_cpu": cores, "template_memory": int(memory * 1024), "template_description": mxn["title"], "template_disk": disk, }) templates[aux["template_id"]] = aux return templates
def _handle_response(self, response): if not response: msg = "Invalid response from OpenNebula's XML RPC endpoint" raise exceptions.OpenNebulaProviderException(msg) if not response[0]: raise exceptions.OpenNebulaProviderException(response[1]) doc = self.xml_parser.fromstring(response[1].encode("utf-8")) if doc is None: msg = "Invalid XML in response from OpenNebula's XML RPC endpoint" raise exceptions.OpenNebulaProviderException(msg) objects = {} for obj in doc: objects[self._get_xml_string(obj, "ID")] = self._recurse_dict(obj)[1] return objects
def __init__(self, opts, **kwargs): self.rocci_template_dir = opts.rocci_template_dir self.rocci_remote_templates = opts.rocci_remote_templates if not self.rocci_template_dir and not self.rocci_remote_templates: msg = ("ERROR, You must provide a rocci_template_dir " "via --rocci-template-dir") raise exceptions.OpenNebulaProviderException(msg) super(OpenNebulaROCCIProvider, self).__init__(opts, **kwargs)
def _handle_response(self, response): if not response: msg = 'Invalid response from OpenNebula\'s XML RPC endpoint' raise exceptions.OpenNebulaProviderException(msg) if not response[0]: raise exceptions.OpenNebulaProviderException(response[1]) doc = self.xml_parser.fromstring(response[1].encode('utf-8')) if doc is None: msg = 'Invalid XML in response from OpenNebula\'s XML RPC endpoint' raise exceptions.OpenNebulaProviderException(msg) objects = {} for obj in doc.getchildren(): objects[self._get_xml_string(obj, 'ID')] = \ self._recurse_dict(obj)[1] return objects
def _read_mixin(json_file): with open(json_file, "r") as fd: jd = json.load(fd) first = jd.get("mixins", [])[0] if not first: msg = "Failed to find a mixin in %s" % (json_file) raise exceptions.OpenNebulaProviderException(msg) return first
def __init__(self, opts): self.rocci_template_dir = opts.rocci_template_dir self.rocci_remote_templates = opts.rocci_remote_templates if not self.rocci_template_dir and not self.rocci_remote_templates: msg = ('ERROR, You must provide a rocci_template_dir ' 'via --rocci-template-dir') raise exceptions.OpenNebulaProviderException(msg) self.ca_info = {} super(OpenNebulaROCCIProvider, self).__init__(opts)
def __init__(self, opts, **kwargs): super(OpenNebulaBaseProvider, self).__init__(opts, **kwargs) self.on_auth = opts.on_auth self.on_rpcxml_endpoint = opts.on_rpcxml_endpoint self.all_images = opts.all_images if not self.on_auth: msg = ("ERROR, You must provide a on_auth " "via either --on-auth or env[ON_AUTH]") raise exceptions.OpenNebulaProviderException(msg) if not self.on_rpcxml_endpoint: msg = ("You must provide an OpenNebula RPC-XML " "endpoint via either --on-rpcxml-endpoint or" " env[ON_RPCXML_ENDPOINT]") raise exceptions.OpenNebulaProviderException(msg) self.static = static.StaticProvider(opts) self.xml_parser = defusedxml.ElementTree self.server_proxy = xmlrpclib.ServerProxy(self.on_rpcxml_endpoint)
import json import os from cloud_info_provider import exceptions, utils from cloud_info_provider.providers import base, static try: import defusedxml.ElementTree from defusedxml import xmlrpc from six.moves import xmlrpc_client as xmlrpclib # nosec # Protect the XMLRPC parser from various XML-based threats xmlrpc.monkey_patch() except ImportError: msg = "Cannot import defusedxml ElementTree and/or xmlrpc." raise exceptions.OpenNebulaProviderException(msg) class OpenNebulaBaseProvider(base.BaseProvider): def __init__(self, opts, **kwargs): super(OpenNebulaBaseProvider, self).__init__(opts, **kwargs) self.on_auth = opts.on_auth self.on_rpcxml_endpoint = opts.on_rpcxml_endpoint self.all_images = opts.all_images if not self.on_auth: msg = ("ERROR, You must provide a on_auth " "via either --on-auth or env[ON_AUTH]") raise exceptions.OpenNebulaProviderException(msg)