Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix novaclient api #55050

Merged
merged 6 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 26 additions & 11 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,9 +270,11 @@ 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 = {}
verify = kwargs.get('verify', False)
Akm0d marked this conversation as resolved.
Show resolved Hide resolved

loader = keystoneauth1.loading.get_plugin_loader(os_auth_plugin or 'password')

Expand Down Expand Up @@ -303,7 +316,9 @@ 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(
Akm0d marked this conversation as resolved.
Show resolved Hide resolved
'catalog', [])
if conn.client.get_endpoint(service_type=identity_service_type).endswith('v3'):
self._v3_setup(region_name)
else:
Expand Down Expand Up @@ -555,10 +570,10 @@ def volume_show(self, name):
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'}
# except Exception as esc:
Akm0d marked this conversation as resolved.
Show resolved Hide resolved
# # volume doesn't exist
# log.error(esc.strerror)
# return {'name': name, 'status': 'deleted'}

return volume

Expand Down Expand Up @@ -728,8 +743,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 +879,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 +914,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