Show instance lock/unlock actions based on the locked status

The server locked information has been added to nova v2.9.

This patch set is to show/hide the lock/unlock actions using
the locked status from nova.

To get the locked status, the compute version needs to be
2.9 or above, which can be set on local_settings.py.

Change-Id: I947c544b32d6056beae97f1c2aa121dd38fb733b
Closes-bug: #1505845
This commit is contained in:
Ying Zuo 2016-01-26 15:50:09 -08:00 committed by David Lyle
parent 21dfd683de
commit abfaf1298a
3 changed files with 11 additions and 6 deletions

View File

@ -50,6 +50,7 @@ LOG = logging.getLogger(__name__)
VERSIONS = base.APIVersionManager("compute", preferred_version=2)
VERSIONS.load_supported_version(1.1, {"client": nova_client, "version": 1.1})
VERSIONS.load_supported_version(2, {"client": nova_client, "version": 2})
VERSIONS.load_supported_version(2.9, {"client": nova_client, "version": 2.9})
# API static values
INSTANCE_ACTIVE_STATE = 'ACTIVE'
@ -97,10 +98,10 @@ class Server(base.APIResourceWrapper):
_attrs = ['addresses', 'attrs', 'id', 'image', 'links',
'metadata', 'name', 'private_ip', 'public_ip', 'status', 'uuid',
'image_name', 'VirtualInterfaces', 'flavor', 'key_name', 'fault',
'tenant_id', 'user_id', 'created', 'OS-EXT-STS:power_state',
'OS-EXT-STS:task_state', 'OS-EXT-SRV-ATTR:instance_name',
'OS-EXT-SRV-ATTR:host', 'OS-EXT-AZ:availability_zone',
'OS-DCF:diskConfig']
'tenant_id', 'user_id', 'created', 'locked',
'OS-EXT-STS:power_state', 'OS-EXT-STS:task_state',
'OS-EXT-SRV-ATTR:instance_name', 'OS-EXT-SRV-ATTR:host',
'OS-EXT-AZ:availability_zone', 'OS-DCF:diskConfig']
def __init__(self, apiresource, request):
super(Server, self).__init__(apiresource)

View File

@ -878,9 +878,11 @@ class LockInstance(policy.PolicyTargetMixin, tables.BatchAction):
count
)
# TODO(akrivoka): When the lock status is added to nova, revisit this
# to only allow unlocked instances to be locked
def allowed(self, request, instance):
# if not locked, lock should be available
if getattr(instance, 'locked', False):
return False
if not api.nova.extension_supported('AdminActions', request):
return False
return True
@ -909,9 +911,10 @@ class UnlockInstance(policy.PolicyTargetMixin, tables.BatchAction):
count
)
# TODO(akrivoka): When the lock status is added to nova, revisit this
# to only allow locked instances to be unlocked
def allowed(self, request, instance):
if not getattr(instance, 'locked', True):
return False
if not api.nova.extension_supported('AdminActions', request):
return False
return True

View File

@ -53,6 +53,7 @@ WEBROOT = '/'
# NOTE: The version should be formatted as it appears in the URL for the
# service API. For example, The identity service APIs have inconsistent
# use of the decimal point, so valid options would be 2.0 or 3.
# Minimum compute version to get the instance locked status is 2.9.
#OPENSTACK_API_VERSIONS = {
# "data-processing": 1.1,
# "identity": 3,