Merge "Enable category management support"
This commit is contained in:
40
muranoclient/v1/categories.py
Normal file
40
muranoclient/v1/categories.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from muranoclient.common import base
|
||||
|
||||
|
||||
class Category(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Category %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class CategoryManager(base.Manager):
|
||||
resource_class = Category
|
||||
|
||||
def list(self):
|
||||
return self._list('/v1/catalog/categories',
|
||||
response_key='categories')
|
||||
|
||||
def get(self, id):
|
||||
return self._get('/v1/catalog/categories/{0}'.format(id))
|
||||
|
||||
def add(self, data):
|
||||
return self._create('/v1/catalog/categories', data)
|
||||
|
||||
def delete(self, id):
|
||||
return self._delete('/v1/catalog/categories/{0}'.format(id))
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
from muranoclient.common import http
|
||||
from muranoclient.v1 import actions
|
||||
from muranoclient.v1 import categories
|
||||
from muranoclient.v1 import deployments
|
||||
from muranoclient.v1 import environments
|
||||
from muranoclient.v1 import instance_statistics
|
||||
@@ -45,3 +46,4 @@ class Client(http.HTTPClient):
|
||||
instance_statistics.InstanceStatisticsManager(self)
|
||||
self.packages = packages.PackageManager(self)
|
||||
self.actions = actions.ActionManager(self)
|
||||
self.categories = categories.CategoryManager(self)
|
||||
|
||||
@@ -109,12 +109,6 @@ def do_deployment_list(mc, args):
|
||||
utils.print_list(deployments, fields, field_labels, sortby=0)
|
||||
|
||||
|
||||
def do_category_list(mc, args):
|
||||
"""List all available categories."""
|
||||
categories = mc.packages.categories()
|
||||
print(categories)
|
||||
|
||||
|
||||
@utils.arg("--include-disabled", default=False, action="store_true")
|
||||
def do_package_list(mc, args={}):
|
||||
"""List available packages."""
|
||||
@@ -279,3 +273,41 @@ def _make_archive(archive_name, path):
|
||||
zip_file.write(os.path.join(root, f),
|
||||
arcname=os.path.join(os.path.relpath(root, path),
|
||||
f))
|
||||
|
||||
|
||||
def do_category_list(mc, args={}):
|
||||
"""List all available categories."""
|
||||
categories = mc.categories.list()
|
||||
|
||||
field_labels = ["ID", "Name", "Packages Assigned"]
|
||||
fields = ["id", "name", "packages"]
|
||||
utils.print_list(categories, fields,
|
||||
field_labels,
|
||||
formatters={'packages':
|
||||
lambda c: '\n'.join(c.packages)})
|
||||
|
||||
|
||||
@utils.arg("name", metavar="<CATEGORY_NAME>",
|
||||
help="Category name")
|
||||
def do_category_create(mc, args):
|
||||
"""Create a category."""
|
||||
mc.categories.add({"name": args.name})
|
||||
do_category_list(mc)
|
||||
|
||||
|
||||
@utils.arg("id", metavar="<ID>",
|
||||
nargs="+", help="Id of a category(s) to delete")
|
||||
def do_category_delete(mc, args):
|
||||
"""Delete a category."""
|
||||
failure_count = 0
|
||||
for category_id in args.id:
|
||||
try:
|
||||
mc.categories.delete(category_id)
|
||||
except exceptions.NotFound:
|
||||
failure_count += 1
|
||||
print("Failed to delete '{0}'; category not found".
|
||||
format(category_id))
|
||||
if failure_count == len(args.id):
|
||||
raise exceptions.CommandError("Unable to find and delete any of the "
|
||||
"specified categories.")
|
||||
do_category_list(mc)
|
||||
|
||||
Reference in New Issue
Block a user