コード例 #1
0
    def get_flavor(self, name):
        """Get the LibCloud size 'flavor' object.

        :param name: flavor name or id
        """
        sizes = self.driver.list_sizes()

        by_name = list(filter(lambda elm: elm.name == name, sizes))
        by_id = list()

        for size in sizes:
            try:
                if name == int(size.id):
                    by_id.append(size)
                    break
            except ValueError:
                # base 10
                continue

        if by_name.__len__() != 0:
            return by_name[0]
        elif by_id.__len__() != 0:
            return by_id[0]
        else:
            raise NotFound('Not found flavor: %s.' % name)
コード例 #2
0
    def resource_check(self, res):
        """Check that the req. resource keys exist.

        :param res: windows resource
        """
        self.logger.info('Checking resource: %s keys.', res['name'])
        for key in PROVISION_RESOURCE_KEYS:
            if key not in res:
                raise NotFound('Resource: %s is missing required key: %s.' %
                               (res['name'], key))
            elif res[key] == '' or res[key] is None:
                raise NotFound(
                    'Resource: %s required key: %s has an invalid value.' %
                    (res['name'], key))
            if key == 'ssh_private_key':
                if not exists(res[key]):
                    raise NotFound('SSH private key: %s not found.' % res[key])
コード例 #3
0
    def credentials(self, value):
        """Set the credentials property.

        This will set the credentials from either file or env vars.

        :param value: provider credentials
        """
        auth = dict()

        self.logger.debug('%s credentials check.', self.name)

        if value:
            self.logger.debug('%s credentials are set by file.', self.name)
            for key in OPENSTACK_ENV_VARS:
                key = key.lower()
                if key not in value:
                    raise NotFound('%s credential: %s is not set.' %
                                   (self.name, key))
                elif value[key] == '' or value[key] is None:
                    raise NotFound('%s credential: %s is not set '
                                   'properly.' % (self.name, key))
                auth[key] = value[key]
        else:
            self.logger.debug('%s credentials are set by env vars.', self.name)

            for key in OPENSTACK_ENV_VARS:
                if key.lower() == 'os_project_name':
                    auth[key.lower()] = getenv(key)
                    if auth[key.lower()] is None:
                        auth[key.lower()] = getenv('OS_TENANT_NAME')
                        if auth[key.lower()] is None:
                            raise NotFound(
                                'Neither [os_project_name|os_tenant_name] env'
                                ' vars is not set.')
                else:
                    auth[key.lower()] = getenv(key)
                    if auth[key.lower()] is None:
                        raise NotFound('Env variable: %s is not found.' % key)
        self._credentials = auth
コード例 #4
0
    def get_network(self, name):
        """Get the LibCloud network object.

        :param name: network name
        """
        networks = self.driver.ex_list_networks()

        data = list(filter(lambda elm: elm.name == name, networks))

        if data.__len__() == 0:
            raise NotFound('Not found network: %s.' % name)
        else:
            return data[0]
コード例 #5
0
    def get_node(self, name):
        """Get the LibCloud node object.

        :param name: vm name
        """
        nodes = self.driver.list_nodes()

        data = list(filter(lambda elm: elm.name == name, nodes))

        if data.__len__() == 0:
            raise NotFound('Not found vm: %s.' % name)
        else:
            return data[0]
コード例 #6
0
    def get_float_ip_pool(self, name):
        """Get the LibCloud floating ip pool object.

        :param name: floating ip pool name
        """
        pool = self.driver.ex_list_floating_ip_pools()

        data = list(filter(lambda elm: elm.name == name, pool))

        if data.__len__() == 0:
            raise NotFound('Not found floating ip pool: %s.' % name)
        else:
            return data[0]
コード例 #7
0
    def get_key_pair(self, name):
        """Get the LibCloud key pair object.

        :param name: key pair name
        """
        pairs = self.driver.list_key_pairs()

        data = list(filter(lambda elm: elm.name == name, pairs))

        if data.__len__() == 0:
            raise NotFound('Not found key pair: %s.' % name)
        else:
            return data[0]
コード例 #8
0
    def get_image(self, name):
        """Get the LibCloud image object.

        :param name: image name or id
        """
        images = self.driver.list_images()

        by_name = list(filter(lambda elm: elm.name == name, images))
        by_id = list(filter(lambda elm: elm.id == name, images))

        if by_name.__len__() != 0:
            return by_name[0]
        elif by_id.__len__() != 0:
            return by_id[0]
        else:
            raise NotFound('Not found image: %s.' % name)