Add package update to openstack CLI
usage: openstack package update [-h] [-f {json,shell,table,value,yaml}] [-c COLUMN] [--max-width <integer>] [--print-empty] [--noindent] [--prefix PREFIX] [--is-public {true|false}] [--enabled {true|false}] [--name NAME] [--description DESCRIPTION] [--tags [<TAG> [<TAG> ...]]] <ID> Update an existing package. Partially implements: blueprint openstack-client-plugin-support Change-Id: Ia287c3202a3698790f8130cd87311b33aa92f5f2
This commit is contained in:
parent
2fbfc68f8a
commit
54a1c60570
|
@ -13,6 +13,7 @@
|
|||
"""Application-catalog v1 package action implementation"""
|
||||
|
||||
import collections
|
||||
import functools
|
||||
import itertools
|
||||
import os
|
||||
import shutil
|
||||
|
@ -26,6 +27,7 @@ from osc_lib import exceptions as exc
|
|||
from osc_lib import utils
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import strutils
|
||||
|
||||
from muranoclient.apiclient import exceptions
|
||||
from muranoclient.common import exceptions as common_exceptions
|
||||
|
@ -38,6 +40,9 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
DEFAULT_REPO_URL = "http://apps.openstack.org/api/v1/murano_repo/liberty/"
|
||||
|
||||
_bool_from_str_strict = functools.partial(
|
||||
strutils.bool_from_string, strict=True)
|
||||
|
||||
|
||||
class CreatePackage(command.Command):
|
||||
"""Create an application package."""
|
||||
|
@ -673,3 +678,76 @@ class ShowPackage(command.ShowOne):
|
|||
)
|
||||
|
||||
return self.dict2columns(to_display)
|
||||
|
||||
|
||||
class UpdatePackage(command.ShowOne):
|
||||
"""Update an existing package."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UpdatePackage, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar="<ID>",
|
||||
help="Package ID to update.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--is-public',
|
||||
type=_bool_from_str_strict,
|
||||
metavar="{true|false}",
|
||||
help="Make package available to users from other tenants.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--enabled',
|
||||
type=_bool_from_str_strict,
|
||||
metavar="{true|false}",
|
||||
help="Make package active and available for deployments.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
default=None,
|
||||
help="New name for the package.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
default=None,
|
||||
help="New package description.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--tags',
|
||||
metavar='<TAG>', nargs='*',
|
||||
default=None,
|
||||
help="A list of keywords connected to the application.",
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
LOG.debug("take_action({0})".format(parsed_args))
|
||||
client = self.app.client_manager.application_catalog
|
||||
data = {}
|
||||
parameters = ('is_public', 'enabled',
|
||||
'name', 'description',
|
||||
'tags')
|
||||
for parameter in parameters:
|
||||
param_value = getattr(parsed_args, parameter, None)
|
||||
if param_value is not None:
|
||||
data[parameter] = param_value
|
||||
|
||||
_, package = client.packages.update(parsed_args.id, data)
|
||||
|
||||
to_display = dict(
|
||||
id=package["id"],
|
||||
type=package["type"],
|
||||
owner_id=package["owner_id"],
|
||||
name=package["name"],
|
||||
fully_qualified_name=package["fully_qualified_name"],
|
||||
is_public=package["is_public"],
|
||||
enabled=package["enabled"],
|
||||
class_definitions=jsonutils.dumps(package["class_definitions"],
|
||||
indent=2),
|
||||
categories=jsonutils.dumps(package["categories"], indent=2),
|
||||
tags=jsonutils.dumps(package["tags"], indent=2),
|
||||
description=package["description"]
|
||||
)
|
||||
|
||||
return self.dict2columns(to_display)
|
||||
|
|
|
@ -712,3 +712,49 @@ class TestShowPackage(TestPackage):
|
|||
self.assertEqual(expected_columns, columns)
|
||||
|
||||
self.package_mock.get.assert_called_with('fake')
|
||||
|
||||
|
||||
class TestUpdatePackage(TestPackage):
|
||||
def setUp(self):
|
||||
super(TestUpdatePackage, self).setUp()
|
||||
|
||||
self.package_mock.update.return_value = \
|
||||
(mock.MagicMock(), mock.MagicMock())
|
||||
|
||||
# Command to test
|
||||
self.cmd = osc_pkg.UpdatePackage(self.app, None)
|
||||
|
||||
def test_package_update(self):
|
||||
arglist = ['123', '--is-public', 'true']
|
||||
verifylist = [('id', '123'), ('is_public', True)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.package_mock.update.assert_called_with('123', {'is_public': True})
|
||||
|
||||
arglist = ['123', '--enabled', 'true']
|
||||
verifylist = [('id', '123'), ('enabled', True)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.package_mock.update.assert_called_with('123', {'enabled': True})
|
||||
|
||||
arglist = ['123', '--name', 'foo', '--description', 'bar']
|
||||
verifylist = [('id', '123'), ('name', 'foo'), ('description', 'bar')]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.package_mock.update.assert_called_with(
|
||||
'123', {'name': 'foo', 'description': 'bar'})
|
||||
|
||||
arglist = ['123', '--tags', 'foo']
|
||||
verifylist = [('id', '123'), ('tags', ['foo'])]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.package_mock.update.assert_called_with(
|
||||
'123', {'tags': ['foo']})
|
||||
|
|
|
@ -57,6 +57,7 @@ openstack.application_catalog.v1 =
|
|||
package_delete = muranoclient.osc.v1.package:DeletePackage
|
||||
package_import = muranoclient.osc.v1.package:ImportPackage
|
||||
package_show = muranoclient.osc.v1.package:ShowPackage
|
||||
package_update = muranoclient.osc.v1.package:UpdatePackage
|
||||
|
||||
bundle_import = muranoclient.osc.v1.package:ImportBundle
|
||||
|
||||
|
|
Loading…
Reference in New Issue