Merge "Added a CLI command to manage categories"
This commit is contained in:
commit
51ddaac328
@ -25,6 +25,7 @@ import muranoapi
|
|||||||
from muranoapi.common import consts
|
from muranoapi.common import consts
|
||||||
from muranoapi.db.catalog import api as db_catalog_api
|
from muranoapi.db.catalog import api as db_catalog_api
|
||||||
from muranoapi.db import session as db_session
|
from muranoapi.db import session as db_session
|
||||||
|
from muranoapi.openstack.common.db import exception as db_exception
|
||||||
from muranoapi.openstack.common import log as logging
|
from muranoapi.openstack.common import log as logging
|
||||||
from muranoapi.packages import application_package
|
from muranoapi.packages import application_package
|
||||||
|
|
||||||
@ -76,6 +77,27 @@ def do_import_package():
|
|||||||
_do_import_package(CONF.command.directory, CONF.command.categories)
|
_do_import_package(CONF.command.directory, CONF.command.categories)
|
||||||
|
|
||||||
|
|
||||||
|
def do_list_categories():
|
||||||
|
categories = db_catalog_api.category_get_names()
|
||||||
|
|
||||||
|
if categories:
|
||||||
|
print(">> Murano package categories:")
|
||||||
|
for c in categories:
|
||||||
|
print("* {0}".format(c))
|
||||||
|
else:
|
||||||
|
print("No categories were found")
|
||||||
|
|
||||||
|
|
||||||
|
def do_add_category():
|
||||||
|
category_name = CONF.command.category_name
|
||||||
|
|
||||||
|
try:
|
||||||
|
db_catalog_api.category_add(category_name)
|
||||||
|
print(">> Successfully added category {0}".format(category_name))
|
||||||
|
except db_exception.DBDuplicateEntry:
|
||||||
|
print(">> ERROR: Category '{0}' already exists".format(category_name))
|
||||||
|
|
||||||
|
|
||||||
def add_command_parsers(subparsers):
|
def add_command_parsers(subparsers):
|
||||||
parser = subparsers.add_parser('db-sync')
|
parser = subparsers.add_parser('db-sync')
|
||||||
parser.set_defaults(func=do_db_sync)
|
parser.set_defaults(func=do_db_sync)
|
||||||
@ -93,6 +115,14 @@ def add_command_parsers(subparsers):
|
|||||||
help='An optional list of categories this package '
|
help='An optional list of categories this package '
|
||||||
'to be assigned to.')
|
'to be assigned to.')
|
||||||
|
|
||||||
|
parser = subparsers.add_parser('category-list')
|
||||||
|
parser.set_defaults(func=do_list_categories)
|
||||||
|
|
||||||
|
parser = subparsers.add_parser('category-add')
|
||||||
|
parser.set_defaults(func=do_add_category)
|
||||||
|
parser.add_argument('category_name',
|
||||||
|
help='Name of the new category.')
|
||||||
|
|
||||||
|
|
||||||
command_opt = cfg.SubCommandOpt('command',
|
command_opt = cfg.SubCommandOpt('command',
|
||||||
title='Commands',
|
title='Commands',
|
||||||
|
@ -31,15 +31,6 @@ SEARCH_MAPPING = {'fqn': 'fully_qualified_name',
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def category_get_names():
|
|
||||||
session = db_session.get_session()
|
|
||||||
categories = []
|
|
||||||
for row in session.query(models.Category.name).all():
|
|
||||||
for name in row:
|
|
||||||
categories.append(name)
|
|
||||||
return categories
|
|
||||||
|
|
||||||
|
|
||||||
def _package_get(package_id, session):
|
def _package_get(package_id, session):
|
||||||
package = session.query(models.Package).get(package_id)
|
package = session.query(models.Package).get(package_id)
|
||||||
if not package:
|
if not package:
|
||||||
@ -390,3 +381,23 @@ def package_delete(package_id):
|
|||||||
def categories_list():
|
def categories_list():
|
||||||
session = db_session.get_session()
|
session = db_session.get_session()
|
||||||
return session.query(models.Category).all()
|
return session.query(models.Category).all()
|
||||||
|
|
||||||
|
|
||||||
|
def category_get_names():
|
||||||
|
session = db_session.get_session()
|
||||||
|
categories = []
|
||||||
|
for row in session.query(models.Category.name).all():
|
||||||
|
for name in row:
|
||||||
|
categories.append(name)
|
||||||
|
return categories
|
||||||
|
|
||||||
|
|
||||||
|
def category_add(category_name):
|
||||||
|
session = db_session.get_session()
|
||||||
|
category = models.Category()
|
||||||
|
|
||||||
|
with session.begin():
|
||||||
|
category.update({'name': category_name})
|
||||||
|
category.save(session)
|
||||||
|
|
||||||
|
return category
|
||||||
|
Loading…
Reference in New Issue
Block a user