def __init__(self, key, secret=None, secure=True, host=None, path=None, port=None, *args, **kwargs): """ @inherits: L{NodeDriver.__init__} @param host: The host where the API can be reached. (required) @type host: C{str} @param path: The host where the API can be reached. (required) @type path: C{str} """ host = host if host else self.host if path is not None: self.path = path if host is not None: self.host = host if (self.type == Provider.CLOUDSTACK) and (not host or not path): raise Exception('When instantiating CloudStack driver directly ' + 'you also need to provide host and path argument') NodeDriver.__init__(self, key=key, secret=secret, secure=secure, host=host, port=port)
def __init__(self, key): """Instantiate the driver with the given API key @keyword key: the API key to use @type key: C{str}""" self.datacenter = None NodeDriver.__init__(self, key)
def __init__(self, key, secret=None, secure=True, host=None, path=None, port=None, *args, **kwargs): host = host if host else self.host if path is not None: self.path = path if host is not None: self.host = host if (self.type == Provider.CLOUDSTACK) and (not host or not path): raise Exception('When instantiating CloudStack driver directly ' + 'you also need to provide host and path argument') NodeDriver.__init__(self, key=key, secret=secret, secure=secure, host=host, port=port)
def __init__(self, key, secret, ex_project_id, ex_consumer_key=None, region=None): """ Instantiate the driver with the given API credentials. :param key: Your application key (required) :type key: ``str`` :param secret: Your application secret (required) :type secret: ``str`` :param ex_project_id: Your project ID :type ex_project_id: ``str`` :param ex_consumer_key: Your consumer key (required) :type ex_consumer_key: ``str`` :param region: The datacenter to connect to (optional) :type region: ``str`` :rtype: ``None`` """ self.region = region self.project_id = ex_project_id self.consumer_key = ex_consumer_key NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key, region=region)
def __init__(self, key): """Instantiate the driver with the given API key @param key: the API key to use (required) @type key: C{str} @rtype: C{None} """ self.datacenter = None NodeDriver.__init__(self, key)
def __init__(self, key): """Instantiate the driver with the given API key :param key: the API key to use (required) :type key: ``str`` :rtype: ``None`` """ self.datacenter = None NodeDriver.__init__(self, key)
def __init__(self, cloud, config): """ Sets `cloud`, `credentials`, `default`, and `cm` values. :param cloud: :param config: """ super().__init__(cloud, config) self.driver = NodeDriver("") self.default_image = None self.default_size = None self.public_key_path = config["profile"]["key"]["public"]
def __init__(self, key, secret, ex_consumer_key=None): """ Instantiate the driver with the given API credentials. :param key: Your application key (required) :type key: ``str`` :param secret: Your application secret (required) :type secret: ``str`` :param ex_consumer_key: Your consumer key (required) :type ex_consumer_key: ``str`` :rtype: ``None`` """ self.datacenter = None self.consumer_key = ex_consumer_key NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key)
def test_get_auth_password(self): n = NodeDriver('foo') n.features = {'create_node': ['password']} auth = NodeAuthPassword('password') self.assertEqual(auth, n._get_and_check_auth(auth))
class LibcloudBaseProvider(ComputeNodeABC): """ Base class for LibCloud based providers. Has default calls for NodeDriver methods that typically don't require any different processing for different clouds or `ex_` methods. """ def __init__(self, cloud, config): """ Sets `cloud`, `credentials`, `default`, and `cm` values. :param cloud: :param config: """ super().__init__(cloud, config) self.driver = NodeDriver("") self.default_image = None self.default_size = None self.public_key_path = config["profile"]["key"]["public"] def create(self, name=None, image=None, size=None, timeout=360, **kwargs): """ creates a named node :return: """ return self.driver.create_node(name=name, image=image or self._get_default_image(), size=image or self._get_default_size(), **kwargs) def nodes(self): """ list all nodes id :return: an array of libcloud Node objects """ return self.driver.list_nodes() def info(self, name=None): """ get info for one node in the list of nodes :param name: :return: """ node = next(filter(lambda n: n.name == name, self.nodes()), None) return node def suspend(self, name=None): return self.stop(name) def resume(self, name=None): """ resume the named node :param name: the name of the node :return: the dict of the node """ return self.start(name) def destroy(self, name=None): """ Destroys the node :param name: the name of the node :return: the dict of the node """ node = self.info(name) self.driver.destroy_node(node) return node @DatabaseUpdate("sizes", ComputeNodeABC.map_default) def list_sizes(self): """ list all sizes available from this provider :return: """ return self.driver.list_sizes() @DatabaseUpdate("locations", ComputeNodeABC.map_default) def list_locations(self): """ list all sizes available from this provider :return: """ return self.driver.list_locations() def _get_default_image(self): """ Get an image object corresponding to teh default image id in config. :return: """ if self.default_image is None: self.default_image = self.driver.get_image(self.default["image"]) return self.default_image def _get_default_size(self): """ Get an size object corresponding to teh default image id in config. :return: """ if self.default_size is None: sizes = self.list_sizes() self.default_size = [ s for s in sizes if s["id"] == self.default["size"] ][0] return dotdict(self.default_size) def start(self, name): pass def stop(self, name=None): pass
def get_metadata(driver: NodeDriver, node: Node) -> collections.abc.Mapping: return driver.ex_get_metadata(node)
def test_base_node_driver(self): NodeDriver("foo")
def test_get_auth_default_no_feature(self): n = NodeDriver('foo') self.assertEqual(None, n._get_and_check_auth(None))
def test_get_auth_password(self): n = NodeDriver("foo") n.features = {"create_node": ["password"]} auth = NodeAuthPassword("password") self.assertEqual(auth, n._get_and_check_auth(auth))
def test_base_node_driver(self): NodeDriver('foo')
def test_get_auth_generates_password_but_given_nonsense(self): n = NodeDriver('foo') n.features = {'create_node': ['generates_password']} auth = "nonsense" self.assertRaises(LibcloudError, n._get_and_check_auth, auth)
def get_metadata(driver: NodeDriver, node: Node) -> Mapping[str, object]: return driver.ex_get_metadata(node)
def get_metadata(driver: NodeDriver, node: Node) -> Mapping[str, object]: return driver.ex_get_metadata_for_node(node)
def test_get_auth_default_password(self): n = NodeDriver("foo") n.features = {"create_node": ["password"]} auth = n._get_and_check_auth(None) self.assertTrue(isinstance(auth, NodeAuthPassword))
def test_get_auth_default_ssh_key(self): n = NodeDriver("foo") n.features = {"create_node": ["ssh_key"]} self.assertEqual(None, n._get_and_check_auth(None))
def test_get_auth_password_but_given_ssh_key(self): n = NodeDriver("foo") n.features = {"create_node": ["password"]} auth = NodeAuthSSHKey("publickey") self.assertRaises(LibcloudError, n._get_and_check_auth, auth)
def test_get_auth_no_features_but_given_nonsense(self): n = NodeDriver('foo') auth = "nonsense" self.assertRaises(LibcloudError, n._get_and_check_auth, auth)
def test_get_auth_default_ssh_key(self): n = NodeDriver('foo') n.features = {'create_node': ['ssh_key']} self.assertEqual(None, n._get_and_check_auth(None))
def test_get_auth_ssh(self): n = NodeDriver('foo') n.features = {'create_node': ['ssh_key']} auth = NodeAuthSSHKey('pubkey...') self.assertEqual(auth, n._get_and_check_auth(auth))
def test_get_auth_ssh(self): n = NodeDriver("foo") n.features = {"create_node": ["ssh_key"]} auth = NodeAuthSSHKey("pubkey...") self.assertEqual(auth, n._get_and_check_auth(auth))
def test_get_auth_password_but_given_ssh_key(self): n = NodeDriver('foo') n.features = {'create_node': ['password']} auth = NodeAuthSSHKey('publickey') self.assertRaises(LibcloudError, n._get_and_check_auth, auth)
def __init__(self, key): self.location = None NodeDriver.__init__(self, key)
def test_get_auth_default_password(self): n = NodeDriver('foo') n.features = {'create_node': ['password']} auth = n._get_and_check_auth(None) self.assertTrue(isinstance(auth, NodeAuthPassword))
def get_metadata(driver: NodeDriver, node: Node) -> typing.Mapping: return driver.ex_get_metadata(node)
def test_get_auth_generates_password_but_given_nonsense(self): n = NodeDriver("foo") n.features = {"create_node": ["generates_password"]} auth = "nonsense" self.assertRaises(LibcloudError, n._get_and_check_auth, auth)