def _create_vgpu_trait(self, resource_provider_id):
     logging.info('Creating trait {}...'.format(self.trait_name))
     command = (
         'openstack {} --os-placement-api-version 1.6 trait create {}')
     command = command.format(openstack_utils.get_cli_auth_args(
         self.keystone_client), self.trait_name)
     first_unit_name = self._get_vgpu_unit_names()[0]
     juju_utils.remote_run(first_unit_name, remote_cmd=command, timeout=180,
                           fatal=True)
     command = (
         'openstack {} --os-placement-api-version 1.6 resource provider '
         'trait set --trait {} {}')
     command = command.format(openstack_utils.get_cli_auth_args(
         self.keystone_client), self.trait_name, resource_provider_id)
     juju_utils.remote_run(first_unit_name, remote_cmd=command, timeout=180,
                           fatal=True)
Beispiel #2
0
    def __init__(self, keystone_client):
        """Initialise helper.

        :param keystone_client: keystone client
        :type keystone_client: keystoneclient.v3
        """
        self.trilio_wlm_unit = zaza_model.get_first_unit_name("trilio-wlm")
        self.auth_args = openstack_utils.get_cli_auth_args(keystone_client)
 def _cleanup_vgpu_trait(self):
     logging.info('Cleaning up trait {}...'.format(self.trait_name))
     command = (
         'openstack {} --os-placement-api-version 1.6 trait delete {}')
     command = command.format(openstack_utils.get_cli_auth_args(
         self.keystone_client), self.trait_name)
     juju_utils.remote_run(
         self._get_vgpu_unit_names()[0], remote_cmd=command, timeout=180,
         fatal=False)
 def _assign_vgpu_trait_to_flavor(self, flavor_name):
     logging.info('Assigning trait {} to flavor {} ...'.format(
         self.trait_name, flavor_name))
     command = (
         'openstack {} flavor set {} --property resources:VGPU=1 '
         '--property trait:{}=required')
     command = command.format(openstack_utils.get_cli_auth_args(
         self.keystone_client), flavor_name, self.trait_name)
     juju_utils.remote_run(
         self._get_vgpu_unit_names()[0], remote_cmd=command, timeout=180,
         fatal=True)
 def _get_num_vgpu_used(self, resource_provider_id):
     logging.info('Querying resource provider inventory...')
     command = (
         'openstack {} resource provider inventory list {} '
         '-f value -c used')
     command = command.format(openstack_utils.get_cli_auth_args(
         self.keystone_client), resource_provider_id)
     num_vgpu_used = juju_utils.remote_run(
         self._get_vgpu_unit_names()[0], remote_cmd=command, timeout=180,
         fatal=True).strip()
     return int(num_vgpu_used)
    def _get_vgpu_resource_provider_id(self, wanted_gpu_address):
        logging.info('Querying resource providers...')
        command = (
            'openstack {} resource provider list -f value -c uuid -c name')
        command = command.format(openstack_utils.get_cli_auth_args(
            self.keystone_client))
        resource_providers = juju_utils.remote_run(
            self._get_vgpu_unit_names()[0], remote_cmd=command, timeout=180,
            fatal=True).strip().split('\n')

        # At this point resource_providers should look like
        # ['0e1379b8-7bd1-40e6-9f41-93cb5b95e38b node-sparky.maas',
        #  '1bb845a4-cf21-44c2-896e-e877760ad39b \
        #   node-sparky.maas_pci_0000_c1_00_0']
        resource_provider_id = None
        wanted_resource_provider_substring = 'pci_{}'.format(
            wanted_gpu_address.replace(':', '_').replace('.', '_'))
        for resource_provider in resource_providers:
            if wanted_resource_provider_substring in resource_provider:
                resource_provider_id = resource_provider.split()[0]
        self.assertIsNotNone(resource_provider_id)
        return resource_provider_id