Merge "volume: Make better use of argparse"
This commit is contained in:
commit
d10185380b
openstackclient
@ -80,8 +80,7 @@ class TestTypeCreate(TestType):
|
|||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("description", self.new_volume_type.description),
|
("description", self.new_volume_type.description),
|
||||||
("public", True),
|
("is_public", True),
|
||||||
("private", False),
|
|
||||||
("name", self.new_volume_type.name),
|
("name", self.new_volume_type.name),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -107,8 +106,7 @@ class TestTypeCreate(TestType):
|
|||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("description", self.new_volume_type.description),
|
("description", self.new_volume_type.description),
|
||||||
("public", False),
|
("is_public", False),
|
||||||
("private", True),
|
|
||||||
("project", self.project.id),
|
("project", self.project.id),
|
||||||
("name", self.new_volume_type.name),
|
("name", self.new_volume_type.name),
|
||||||
]
|
]
|
||||||
@ -325,8 +323,7 @@ class TestTypeList(TestType):
|
|||||||
arglist = []
|
arglist = []
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("long", False),
|
("long", False),
|
||||||
("private", False),
|
("is_public", None),
|
||||||
("public", False),
|
|
||||||
("default", False),
|
("default", False),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -343,8 +340,7 @@ class TestTypeList(TestType):
|
|||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("long", True),
|
("long", True),
|
||||||
("private", False),
|
("is_public", True),
|
||||||
("public", True),
|
|
||||||
("default", False),
|
("default", False),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -360,8 +356,7 @@ class TestTypeList(TestType):
|
|||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("long", False),
|
("long", False),
|
||||||
("private", True),
|
("is_public", False),
|
||||||
("public", False),
|
|
||||||
("default", False),
|
("default", False),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@ -378,8 +373,7 @@ class TestTypeList(TestType):
|
|||||||
verifylist = [
|
verifylist = [
|
||||||
("encryption_type", False),
|
("encryption_type", False),
|
||||||
("long", False),
|
("long", False),
|
||||||
("private", False),
|
("is_public", None),
|
||||||
("public", False),
|
|
||||||
("default", True),
|
("default", True),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
@ -124,13 +124,15 @@ class CreateVolumeType(command.ShowOne):
|
|||||||
public_group.add_argument(
|
public_group.add_argument(
|
||||||
"--public",
|
"--public",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
dest="is_public",
|
||||||
|
default=None,
|
||||||
help=_("Volume type is accessible to the public"),
|
help=_("Volume type is accessible to the public"),
|
||||||
)
|
)
|
||||||
public_group.add_argument(
|
public_group.add_argument(
|
||||||
"--private",
|
"--private",
|
||||||
action="store_true",
|
action="store_false",
|
||||||
default=False,
|
dest="is_public",
|
||||||
|
default=None,
|
||||||
help=_("Volume type is not accessible to the public"),
|
help=_("Volume type is not accessible to the public"),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -201,15 +203,13 @@ class CreateVolumeType(command.ShowOne):
|
|||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
|
|
||||||
if parsed_args.project and not parsed_args.private:
|
if parsed_args.project and parsed_args.is_public is not False:
|
||||||
msg = _("--project is only allowed with --private")
|
msg = _("--project is only allowed with --private")
|
||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if parsed_args.public:
|
if parsed_args.is_public is not None:
|
||||||
kwargs['is_public'] = True
|
kwargs['is_public'] = parsed_args.is_public
|
||||||
if parsed_args.private:
|
|
||||||
kwargs['is_public'] = False
|
|
||||||
|
|
||||||
volume_type = volume_client.volume_types.create(
|
volume_type = volume_client.volume_types.create(
|
||||||
parsed_args.name, description=parsed_args.description, **kwargs
|
parsed_args.name, description=parsed_args.description, **kwargs
|
||||||
@ -329,11 +329,15 @@ class ListVolumeType(command.Lister):
|
|||||||
public_group.add_argument(
|
public_group.add_argument(
|
||||||
"--public",
|
"--public",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
dest="is_public",
|
||||||
|
default=None,
|
||||||
help=_("List only public types"),
|
help=_("List only public types"),
|
||||||
)
|
)
|
||||||
public_group.add_argument(
|
public_group.add_argument(
|
||||||
"--private",
|
"--private",
|
||||||
action="store_true",
|
action="store_false",
|
||||||
|
dest="is_public",
|
||||||
|
default=None,
|
||||||
help=_("List only private types (admin only)"),
|
help=_("List only private types (admin only)"),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -348,8 +352,15 @@ class ListVolumeType(command.Lister):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
|
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = ['ID', 'Name', 'Is Public', 'Description', 'Extra Specs']
|
columns = [
|
||||||
|
'ID',
|
||||||
|
'Name',
|
||||||
|
'Is Public',
|
||||||
|
'Description',
|
||||||
|
'Extra Specs',
|
||||||
|
]
|
||||||
column_headers = [
|
column_headers = [
|
||||||
'ID',
|
'ID',
|
||||||
'Name',
|
'Name',
|
||||||
@ -360,15 +371,13 @@ class ListVolumeType(command.Lister):
|
|||||||
else:
|
else:
|
||||||
columns = ['ID', 'Name', 'Is Public']
|
columns = ['ID', 'Name', 'Is Public']
|
||||||
column_headers = ['ID', 'Name', 'Is Public']
|
column_headers = ['ID', 'Name', 'Is Public']
|
||||||
|
|
||||||
if parsed_args.default:
|
if parsed_args.default:
|
||||||
data = [volume_client.volume_types.default()]
|
data = [volume_client.volume_types.default()]
|
||||||
else:
|
else:
|
||||||
is_public = None
|
data = volume_client.volume_types.list(
|
||||||
if parsed_args.public:
|
is_public=parsed_args.is_public
|
||||||
is_public = True
|
)
|
||||||
if parsed_args.private:
|
|
||||||
is_public = False
|
|
||||||
data = volume_client.volume_types.list(is_public=is_public)
|
|
||||||
|
|
||||||
formatters = {'Extra Specs': format_columns.DictColumn}
|
formatters = {'Extra Specs': format_columns.DictColumn}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user