Revised profile list implementation
This commit is contained in:
parent
9b90617e91
commit
b7677be573
@ -14,6 +14,7 @@ import inspect
|
|||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from openstack import exceptions as exc
|
||||||
from openstack.identity import identity_service
|
from openstack.identity import identity_service
|
||||||
from openstack.network.v2 import thin as thins
|
from openstack.network.v2 import thin as thins
|
||||||
from openstack import transport as trans
|
from openstack import transport as trans
|
||||||
@ -25,11 +26,7 @@ class Client(object):
|
|||||||
self.auth = session.authenticator
|
self.auth = session.authenticator
|
||||||
|
|
||||||
def get_options(self, options):
|
def get_options(self, options):
|
||||||
try:
|
return json.loads(options)
|
||||||
iddy = uuid.UUID(str(options))
|
|
||||||
return {'id': iddy}
|
|
||||||
except ValueError:
|
|
||||||
return json.loads(options)
|
|
||||||
|
|
||||||
def transport(self, opts):
|
def transport(self, opts):
|
||||||
'''Create a transport given some options.
|
'''Create a transport given some options.
|
||||||
@ -59,19 +56,22 @@ class Client(object):
|
|||||||
return xport
|
return xport
|
||||||
|
|
||||||
def list(self, cls, options=None):
|
def list(self, cls, options=None):
|
||||||
objs = cls.list(self.session, path_args=options)
|
try:
|
||||||
return objs
|
result = cls.list(self.session, path_args=options)
|
||||||
|
return result
|
||||||
|
except exc.HttpException as ex:
|
||||||
|
print(ex)
|
||||||
|
return None
|
||||||
|
|
||||||
def list_short(self, cls, options=None):
|
def list_short(self, cls, options=None):
|
||||||
path_args = None
|
try:
|
||||||
if options:
|
return cls.list_short(self.session, path_args=None, **options)
|
||||||
path_args = self.get_options(options)
|
except exc.HttpException as ex:
|
||||||
objs = cls.list_short(self.session, path_args=path_args)
|
print(ex)
|
||||||
return objs
|
return None
|
||||||
|
|
||||||
def create(self, cls, options):
|
def create(self, cls, params):
|
||||||
#kwargs = self.get_options(options)
|
obj = cls.new(**params)
|
||||||
obj = cls.new(**options)
|
|
||||||
return obj.create(self.session)
|
return obj.create(self.session)
|
||||||
|
|
||||||
def get(self, cls, options=None):
|
def get(self, cls, options=None):
|
||||||
@ -94,8 +94,7 @@ class Client(object):
|
|||||||
obj.update(self.session)
|
obj.update(self.session)
|
||||||
|
|
||||||
def delete(self, cls, options):
|
def delete(self, cls, options):
|
||||||
kwargs = self.get_options(options)
|
obj = cls.new(**options)
|
||||||
obj = cls.new(**kwargs)
|
|
||||||
obj.delete(self.session)
|
obj.delete(self.session)
|
||||||
|
|
||||||
def head(self, cls, options):
|
def head(self, cls, options):
|
||||||
|
@ -97,6 +97,8 @@ class Profile(resource.Resource):
|
|||||||
spec = resource.prop('spec', type=dict)
|
spec = resource.prop('spec', type=dict)
|
||||||
permission = resource.prop('permission')
|
permission = resource.prop('permission')
|
||||||
tags = resource.prop('tags', type=dict)
|
tags = resource.prop('tags', type=dict)
|
||||||
|
created_time = resource.prop('created_time')
|
||||||
|
deleted_time = resource.prop('deleted_time')
|
||||||
|
|
||||||
|
|
||||||
class PolicyType(resource.Resource):
|
class PolicyType(resource.Resource):
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
@ -86,15 +87,18 @@ def do_profile_type_template(sc, args):
|
|||||||
help=_('Only return profiles that appear after the given ID.'))
|
help=_('Only return profiles that appear after the given ID.'))
|
||||||
def do_profile_list(sc, args=None):
|
def do_profile_list(sc, args=None):
|
||||||
'''List profiles that meet the criteria.'''
|
'''List profiles that meet the criteria.'''
|
||||||
queries = {}
|
|
||||||
fields = ['id', 'name', 'type', 'permission', 'created_time']
|
fields = ['id', 'name', 'type', 'permission', 'created_time']
|
||||||
if args:
|
queries = {'show_deleted': False}
|
||||||
queries = {'limit': args.limit,
|
if args.limit:
|
||||||
'marker': args.marker,
|
queries['limit'] = args.limit
|
||||||
'show_deleted': args.show_deleted}
|
if args.marker:
|
||||||
|
queries['marker'] = args.marker
|
||||||
|
if args.show_deleted:
|
||||||
|
queries['show_deleted'] = str(bool(args.show_deleted))
|
||||||
|
|
||||||
profiles = sc.list(models.Profile, queries)
|
profiles = sc.list_short(models.Profile, queries)
|
||||||
utils.print_list(profiles, fields, sortby_index=1)
|
if profiles:
|
||||||
|
utils.print_list(profiles, fields, sortby_index=1)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('-t', '--profile-type', metavar='<TYPE NAME>',
|
@utils.arg('-t', '--profile-type', metavar='<TYPE NAME>',
|
||||||
@ -123,8 +127,28 @@ def do_profile_create(sc, args):
|
|||||||
'tags': utils.format_parameters(args.tags),
|
'tags': utils.format_parameters(args.tags),
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.create(models.Profile, params)
|
profile = sc.create(models.Profile, params)
|
||||||
do_profile_list(sc)
|
if profile:
|
||||||
|
print("Profile ID: %s" % profile.id)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('id', metavar='<NAME or ID>', nargs='+',
|
||||||
|
help=_('Name or ID of profile(s) to delete.'))
|
||||||
|
def do_profile_delete(sc, args):
|
||||||
|
'''Delete profile(s).'''
|
||||||
|
failure_count = 0
|
||||||
|
|
||||||
|
for cid in args.id:
|
||||||
|
try:
|
||||||
|
query = {'id': cid}
|
||||||
|
sc.delete(models.Profile, query)
|
||||||
|
except exc.HTTPNotFound as ex:
|
||||||
|
failure_count += 1
|
||||||
|
print(ex)
|
||||||
|
if failure_count == len(args.id):
|
||||||
|
msg = _('Failed to delete any of the specified profile(s).')
|
||||||
|
raise exc.CommandError(msg)
|
||||||
|
print('Profile deleted: %s' % args.id)
|
||||||
|
|
||||||
|
|
||||||
#### POLICY TYPES
|
#### POLICY TYPES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user