Revised profile list implementation
This commit is contained in:
parent
9b90617e91
commit
b7677be573
@ -14,6 +14,7 @@ import inspect
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from openstack import exceptions as exc
|
||||
from openstack.identity import identity_service
|
||||
from openstack.network.v2 import thin as thins
|
||||
from openstack import transport as trans
|
||||
@ -25,11 +26,7 @@ class Client(object):
|
||||
self.auth = session.authenticator
|
||||
|
||||
def get_options(self, options):
|
||||
try:
|
||||
iddy = uuid.UUID(str(options))
|
||||
return {'id': iddy}
|
||||
except ValueError:
|
||||
return json.loads(options)
|
||||
return json.loads(options)
|
||||
|
||||
def transport(self, opts):
|
||||
'''Create a transport given some options.
|
||||
@ -59,19 +56,22 @@ class Client(object):
|
||||
return xport
|
||||
|
||||
def list(self, cls, options=None):
|
||||
objs = cls.list(self.session, path_args=options)
|
||||
return objs
|
||||
try:
|
||||
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):
|
||||
path_args = None
|
||||
if options:
|
||||
path_args = self.get_options(options)
|
||||
objs = cls.list_short(self.session, path_args=path_args)
|
||||
return objs
|
||||
try:
|
||||
return cls.list_short(self.session, path_args=None, **options)
|
||||
except exc.HttpException as ex:
|
||||
print(ex)
|
||||
return None
|
||||
|
||||
def create(self, cls, options):
|
||||
#kwargs = self.get_options(options)
|
||||
obj = cls.new(**options)
|
||||
def create(self, cls, params):
|
||||
obj = cls.new(**params)
|
||||
return obj.create(self.session)
|
||||
|
||||
def get(self, cls, options=None):
|
||||
@ -94,8 +94,7 @@ class Client(object):
|
||||
obj.update(self.session)
|
||||
|
||||
def delete(self, cls, options):
|
||||
kwargs = self.get_options(options)
|
||||
obj = cls.new(**kwargs)
|
||||
obj = cls.new(**options)
|
||||
obj.delete(self.session)
|
||||
|
||||
def head(self, cls, options):
|
||||
|
@ -97,6 +97,8 @@ class Profile(resource.Resource):
|
||||
spec = resource.prop('spec', type=dict)
|
||||
permission = resource.prop('permission')
|
||||
tags = resource.prop('tags', type=dict)
|
||||
created_time = resource.prop('created_time')
|
||||
deleted_time = resource.prop('deleted_time')
|
||||
|
||||
|
||||
class PolicyType(resource.Resource):
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
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.'))
|
||||
def do_profile_list(sc, args=None):
|
||||
'''List profiles that meet the criteria.'''
|
||||
queries = {}
|
||||
fields = ['id', 'name', 'type', 'permission', 'created_time']
|
||||
if args:
|
||||
queries = {'limit': args.limit,
|
||||
'marker': args.marker,
|
||||
'show_deleted': args.show_deleted}
|
||||
queries = {'show_deleted': False}
|
||||
if args.limit:
|
||||
queries['limit'] = args.limit
|
||||
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)
|
||||
utils.print_list(profiles, fields, sortby_index=1)
|
||||
profiles = sc.list_short(models.Profile, queries)
|
||||
if profiles:
|
||||
utils.print_list(profiles, fields, sortby_index=1)
|
||||
|
||||
|
||||
@utils.arg('-t', '--profile-type', metavar='<TYPE NAME>',
|
||||
@ -123,8 +127,28 @@ def do_profile_create(sc, args):
|
||||
'tags': utils.format_parameters(args.tags),
|
||||
}
|
||||
|
||||
sc.create(models.Profile, params)
|
||||
do_profile_list(sc)
|
||||
profile = sc.create(models.Profile, params)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user