Skip to content

Commit

Permalink
Merge pull request #55050 from Akm0d/fix_novaclient_api
Browse files Browse the repository at this point in the history
Fix novaclient api
  • Loading branch information
dwoz authored Jan 2, 2020
2 parents c90447f + f83d68c commit 92fbbf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
5 changes: 4 additions & 1 deletion salt/modules/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
except NameError as exc:
HAS_NOVA = False

# Define the module's virtual name
__virtualname__ = 'nova'


def __virtual__():
'''
Expand Down Expand Up @@ -345,7 +348,7 @@ def volume_attach(name,
.. code-block:: bash
salt '*' nova.volume_attach myblock slice.example.com profile=openstack
salt '*' nova.volume_attach myblock server.example.com device=/dev/xvdb profile=openstack
salt '*' nova.volume_attach myblock server.example.com device='/dev/xvdb' profile=openstack
'''
conn = _auth(profile)
Expand Down
37 changes: 25 additions & 12 deletions salt/utils/openstack/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# Import third party libs
from salt.ext import six

HAS_NOVA = False
# pylint: disable=import-error
try:
Expand All @@ -22,6 +23,7 @@
import novaclient.exceptions
import novaclient.extension
import novaclient.base

HAS_NOVA = True
except ImportError:
pass
Expand All @@ -30,6 +32,7 @@
try:
import keystoneauth1.loading
import keystoneauth1.session

HAS_KEYSTONEAUTH = True
except ImportError:
pass
Expand Down Expand Up @@ -79,6 +82,14 @@ def check_nova():
return False


if check_nova():
try:
import novaclient.auth_plugin
except ImportError:
log.debug('Using novaclient version 7.0.0 or newer. Authentication '
'plugin auth_plugin.py is not available anymore.')


# kwargs has to be an object instead of a dictionary for the __post_parse_arg__
class KwargsStruct(object):
def __init__(self, **entries):
Expand Down Expand Up @@ -199,7 +210,7 @@ def get_endpoint_url_v3(catalog, service_type, region_name):
if service_entry['type'] == service_type:
for endpoint_entry in service_entry['endpoints']:
if (endpoint_entry['region'] == region_name and
endpoint_entry['interface'] == 'public'):
endpoint_entry['interface'] == 'public'):
return endpoint_entry['url']
return None

Expand Down Expand Up @@ -259,7 +270,8 @@ def __init__(
os_auth_plugin=os_auth_plugin,
**kwargs)

def _new_init(self, username, project_id, auth_url, region_name, password, os_auth_plugin, auth=None, verify=True, **kwargs):
def _new_init(self, username, project_id, auth_url, region_name, password, os_auth_plugin, auth=None, verify=True,
**kwargs):
if auth is None:
auth = {}

Expand Down Expand Up @@ -303,7 +315,12 @@ def _new_init(self, username, project_id, auth_url, region_name, password, os_au
conn = client.Client(version=self.version, session=self.session, **self.client_kwargs)
self.kwargs['auth_token'] = conn.client.session.get_token()
identity_service_type = kwargs.get('identity_service_type', 'identity')
self.catalog = conn.client.session.get('/auth/catalog', endpoint_filter={'service_type': identity_service_type}).json().get('catalog', [])
self.catalog = conn.client.session.get(
'/auth/catalog',
endpoint_filter={
'service_type': identity_service_type
}
).json().get('catalog', [])
if conn.client.get_endpoint(service_type=identity_service_type).endswith('v3'):
self._v3_setup(region_name)
else:
Expand Down Expand Up @@ -550,15 +567,11 @@ def volume_show(self, name):
'''
if self.volume_conn is None:
raise SaltCloudSystemExit('No cinder endpoint available')
nt_ks = self.volume_conn

volumes = self.volume_list(
search_opts={'display_name': name},
)
volume = volumes[name]
# except Exception as esc:
# # volume doesn't exist
# log.error(esc.strerror)
# return {'name': name, 'status': 'deleted'}

return volume

Expand Down Expand Up @@ -728,8 +741,8 @@ def flavor_list(self):
list_sizes = flavor_list

def flavor_create(self,
name, # pylint: disable=C0103
flavor_id=0, # pylint: disable=C0103
name, # pylint: disable=C0103
flavor_id=0, # pylint: disable=C0103
ram=0,
disk=0,
vcpus=1):
Expand Down Expand Up @@ -864,7 +877,7 @@ def image_meta_set(self,
return {image_id: kwargs}

def image_meta_delete(self,
image_id=None, # pylint: disable=C0103
image_id=None, # pylint: disable=C0103
name=None,
keys=None):
'''
Expand Down Expand Up @@ -899,7 +912,7 @@ def server_list(self):
'links': item.flavor['links']},
'image': {'id': item.image['id'] if item.image else 'Boot From Volume',
'links': item.image['links'] if item.image else ''},
}
}
except TypeError:
pass
return ret
Expand Down

0 comments on commit 92fbbf1

Please sign in to comment.