Remove aliases for `args` and `env` in utils

To remove aliases for `arg` and `env` functions in novaclient.utils,
we should use `arg` and `env` directly from cliutils in novaclients modules.

This patch removes aliases in `novaclient.utils` and starts using
`args` and `env` from novaclient.openstack.common.cliutils directly.

Change-Id: I4585adae62bc66ad6bc9d19be10d4679bb3dc5a1
This commit is contained in:
Andrey Kurilin 2014-10-24 14:15:17 +03:00
parent 821643e126
commit 96a124fae6
13 changed files with 134 additions and 114 deletions

View File

@ -45,8 +45,8 @@ from six.moves.urllib import parse
from novaclient import exceptions
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import service_catalog
from novaclient import utils
class _ClientConnectionPool(object):
@ -90,8 +90,8 @@ class CompletionCache(object):
"""
uniqifier = hashlib.md5(username.encode('utf-8') +
auth_url.encode('utf-8')).hexdigest()
base_dir = utils.env('NOVACLIENT_UUID_CACHE_DIR',
default="~/.novaclient")
base_dir = cliutils.env('NOVACLIENT_UUID_CACHE_DIR',
default="~/.novaclient")
return os.path.expanduser(os.path.join(base_dir, uniqifier))
def _prepare_directory(self):

View File

@ -159,7 +159,7 @@ class SecretsHelper(object):
self._password = self.args.os_password
else:
verify_pass = strutils.bool_from_string(
utils.env("OS_VERIFY_PASSWORD", default=False), True)
cliutils.env("OS_VERIFY_PASSWORD", default=False), True)
self._password = self._prompt_password(verify_pass)
if not self._password:
raise exc.CommandError(
@ -241,16 +241,17 @@ class OpenStackComputeShell(object):
# Register the CLI arguments that have moved to the session object.
ksession.Session.register_cli_options(parser)
parser.set_defaults(insecure=utils.env('NOVACLIENT_INSECURE',
parser.set_defaults(insecure=cliutils.env('NOVACLIENT_INSECURE',
default=False))
identity.Password.register_argparse_arguments(parser)
parser.set_defaults(os_username=utils.env('OS_USERNAME',
'NOVA_USERNAME'))
parser.set_defaults(os_password=utils.env('OS_PASSWORD',
'NOVA_PASSWORD'))
parser.set_defaults(os_auth_url=utils.env('OS_AUTH_URL', 'NOVA_URL'))
parser.set_defaults(os_username=cliutils.env('OS_USERNAME',
'NOVA_USERNAME'))
parser.set_defaults(os_password=cliutils.env('OS_PASSWORD',
'NOVA_PASSWORD'))
parser.set_defaults(os_auth_url=cliutils.env('OS_AUTH_URL',
'NOVA_URL'))
def get_base_parser(self):
parser = NovaClientArgumentParser(
@ -282,7 +283,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-cache',
default=strutils.bool_from_string(
utils.env('OS_CACHE', default=False), True),
cliutils.env('OS_CACHE', default=False), True),
action='store_true',
help=_("Use the auth token cache. Defaults to False if "
"env[OS_CACHE] is not set."))
@ -295,7 +296,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-auth-token',
default=utils.env('OS_AUTH_TOKEN'),
default=cliutils.env('OS_AUTH_TOKEN'),
help='Defaults to env[OS_AUTH_TOKEN]')
parser.add_argument(
@ -309,7 +310,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-tenant-name',
metavar='<auth-tenant-name>',
default=utils.env('OS_TENANT_NAME', 'NOVA_PROJECT_ID'),
default=cliutils.env('OS_TENANT_NAME', 'NOVA_PROJECT_ID'),
help=_('Defaults to env[OS_TENANT_NAME].'))
parser.add_argument(
'--os_tenant_name',
@ -318,7 +319,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-tenant-id',
metavar='<auth-tenant-id>',
default=utils.env('OS_TENANT_ID'),
default=cliutils.env('OS_TENANT_ID'),
help=_('Defaults to env[OS_TENANT_ID].'))
parser.add_argument(
@ -328,7 +329,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-region-name',
metavar='<region-name>',
default=utils.env('OS_REGION_NAME', 'NOVA_REGION_NAME'),
default=cliutils.env('OS_REGION_NAME', 'NOVA_REGION_NAME'),
help=_('Defaults to env[OS_REGION_NAME].'))
parser.add_argument(
'--os_region_name',
@ -337,7 +338,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-auth-system',
metavar='<auth-system>',
default=utils.env('OS_AUTH_SYSTEM'),
default=cliutils.env('OS_AUTH_SYSTEM'),
help='Defaults to env[OS_AUTH_SYSTEM].')
parser.add_argument(
'--os_auth_system',
@ -354,7 +355,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--service-name',
metavar='<service-name>',
default=utils.env('NOVA_SERVICE_NAME'),
default=cliutils.env('NOVA_SERVICE_NAME'),
help=_('Defaults to env[NOVA_SERVICE_NAME]'))
parser.add_argument(
'--service_name',
@ -363,7 +364,7 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--volume-service-name',
metavar='<volume-service-name>',
default=utils.env('NOVA_VOLUME_SERVICE_NAME'),
default=cliutils.env('NOVA_VOLUME_SERVICE_NAME'),
help=_('Defaults to env[NOVA_VOLUME_SERVICE_NAME]'))
parser.add_argument(
'--volume_service_name',
@ -373,9 +374,9 @@ class OpenStackComputeShell(object):
'--os-endpoint-type',
metavar='<endpoint-type>',
dest='endpoint_type',
default=utils.env(
default=cliutils.env(
'NOVA_ENDPOINT_TYPE',
default=utils.env(
default=cliutils.env(
'OS_ENDPOINT_TYPE',
default=DEFAULT_NOVA_ENDPOINT_TYPE)),
help=_('Defaults to env[NOVA_ENDPOINT_TYPE], '
@ -395,8 +396,8 @@ class OpenStackComputeShell(object):
parser.add_argument(
'--os-compute-api-version',
metavar='<compute-api-ver>',
default=utils.env('OS_COMPUTE_API_VERSION',
default=DEFAULT_OS_COMPUTE_API_VERSION),
default=cliutils.env('OS_COMPUTE_API_VERSION',
default=DEFAULT_OS_COMPUTE_API_VERSION),
help=_('Accepts 1.1 or 3, '
'defaults to env[OS_COMPUTE_API_VERSION].'))
parser.add_argument(
@ -407,7 +408,7 @@ class OpenStackComputeShell(object):
'--bypass-url',
metavar='<bypass-url>',
dest='bypass_url',
default=utils.env('NOVACLIENT_BYPASS_URL'),
default=cliutils.env('NOVACLIENT_BYPASS_URL'),
help="Use this API endpoint instead of the Service Catalog. "
"Defaults to env[NOVACLIENT_BYPASS_URL]")
parser.add_argument('--bypass_url',
@ -849,7 +850,7 @@ class OpenStackComputeShell(object):
commands.remove('bash_completion')
print(' '.join(commands | options))
@utils.arg(
@cliutils.arg(
'command',
metavar='<subcommand>',
nargs='?',

View File

@ -27,9 +27,6 @@ from novaclient.i18n import _
from novaclient.openstack.common import cliutils
arg = cliutils.arg
env = cliutils.env
VALID_KEY_REGEX = re.compile(r"[\w\.\- :]+$", re.UNICODE)

View File

@ -19,6 +19,7 @@ Baremetal interface (v2 extension).
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -151,43 +152,43 @@ class BareMetalNodeManager(base.ManagerWithFind):
return interfaces
@utils.arg(
@cliutils.arg(
'service_host',
metavar='<service_host>',
help=_('Name of nova compute host which will control this baremetal '
'node'))
@utils.arg(
@cliutils.arg(
'cpus',
metavar='<cpus>',
type=int,
help=_('Number of CPUs in the node'))
@utils.arg(
@cliutils.arg(
'memory_mb',
metavar='<memory_mb>',
type=int,
help=_('Megabytes of RAM in the node'))
@utils.arg(
@cliutils.arg(
'local_gb',
metavar='<local_gb>',
type=int,
help=_('Gigabytes of local storage in the node'))
@utils.arg(
@cliutils.arg(
'prov_mac_address',
metavar='<prov_mac_address>',
help=_('MAC address to provision the node'))
@utils.arg(
@cliutils.arg(
'--pm_address', default=None,
metavar='<pm_address>',
help=_('Power management IP for the node'))
@utils.arg(
@cliutils.arg(
'--pm_user', default=None,
metavar='<pm_user>',
help=_('Username for the node\'s power management'))
@utils.arg(
@cliutils.arg(
'--pm_password', default=None,
metavar='<pm_password>',
help=_('Password for the node\'s power management'))
@utils.arg(
@cliutils.arg(
'--terminal_port', default=None,
metavar='<terminal_port>',
type=int,
@ -204,7 +205,7 @@ def do_baremetal_node_create(cs, args):
_print_baremetal_resource(node)
@utils.arg(
@cliutils.arg(
'node',
metavar='<node>',
help=_('ID of the node to delete.'))
@ -286,7 +287,7 @@ def _print_baremetal_node_interfaces(interfaces):
])
@utils.arg(
@cliutils.arg(
'node',
metavar='<node>',
help=_("ID of node"))
@ -296,20 +297,20 @@ def do_baremetal_node_show(cs, args):
_print_baremetal_resource(node)
@utils.arg(
@cliutils.arg(
'node',
metavar='<node>',
help=_("ID of node"))
@utils.arg(
@cliutils.arg(
'address',
metavar='<address>',
help=_("MAC address of interface"))
@utils.arg(
@cliutils.arg(
'--datapath_id',
default=0,
metavar='<datapath_id>',
help=_("OpenFlow Datapath ID of interface"))
@utils.arg(
@cliutils.arg(
'--port_no',
default=0,
metavar='<port_no>',
@ -321,14 +322,17 @@ def do_baremetal_interface_add(cs, args):
_print_baremetal_resource(bmif)
@utils.arg('node', metavar='<node>', help=_("ID of node"))
@utils.arg('address', metavar='<address>', help=_("MAC address of interface"))
@cliutils.arg('node', metavar='<node>', help=_("ID of node"))
@cliutils.arg(
'address',
metavar='<address>',
help=_("MAC address of interface"))
def do_baremetal_interface_remove(cs, args):
"""Remove a network interface from a baremetal node."""
cs.baremetal.remove_interface(args.node, args.address)
@utils.arg('node', metavar='<node>', help=_("ID of node"))
@cliutils.arg('node', metavar='<node>', help=_("ID of node"))
def do_baremetal_interface_list(cs, args):
"""List network interfaces associated with a baremetal node."""
interfaces = cs.baremetal.list_interfaces(args.node)

View File

@ -15,6 +15,7 @@
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -46,7 +47,7 @@ class CellsManager(base.Manager):
return self._get("/os-cells/%s" % path, "cell")
@utils.arg(
@cliutils.arg(
'cell',
metavar='<cell-name>',
help=_('Name of the cell.'))
@ -56,7 +57,7 @@ def do_cell_show(cs, args):
utils.print_dict(cell._info)
@utils.arg(
@cliutils.arg(
'--cell',
metavar='<cell-name>',
help=_("Name of the cell to get the capacities."),

View File

@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from novaclient.openstack.common import cliutils
from novaclient import utils
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
@cliutils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_force_delete(cs, args):
"""Force delete a server."""
utils.find_resource(cs.servers, args.server).force_delete()
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
@cliutils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_restore(cs, args):
"""Restore a soft-deleted server."""
utils.find_resource(cs.servers, args.server).restore()

View File

@ -15,6 +15,7 @@
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -37,19 +38,19 @@ def _server_evacuate(cs, server, args):
"error_message": error_message})
@utils.arg('host', metavar='<host>', help='Name of host.')
@utils.arg('--target_host',
metavar='<target_host>',
default=None,
help=_('Name of target host. '
'If no host is specified the scheduler'
' will select a target.'))
@utils.arg('--on-shared-storage',
dest='on_shared_storage',
action="store_true",
default=False,
help=_('Specifies whether all instances files are on shared '
' storage'))
@cliutils.arg('host', metavar='<host>', help='Name of host.')
@cliutils.arg(
'--target_host',
metavar='<target_host>',
default=None,
help=_('Name of target host. If no host is specified the scheduler will '
'select a target.'))
@cliutils.arg(
'--on-shared-storage',
dest='on_shared_storage',
action="store_true",
default=False,
help=_('Specifies whether all instances files are on shared storage'))
def do_host_evacuate(cs, args):
"""Evacuate all instances from failed host."""
hypervisors = cs.hypervisors.search(args.host, servers=True)

View File

@ -14,6 +14,7 @@
# under the License.
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -37,19 +38,22 @@ def _server_live_migrate(cs, server, args):
error_message)
@utils.arg('host', metavar='<host>', help='Name of host.')
@utils.arg('--target-host',
metavar='<target_host>',
default=None,
help=_('Name of target host.'))
@utils.arg('--block-migrate',
action='store_true',
default=False,
help=_('Enable block migration.'))
@utils.arg('--disk-over-commit',
action='store_true',
default=False,
help=_('Enable disk overcommit.'))
@cliutils.arg('host', metavar='<host>', help='Name of host.')
@cliutils.arg(
'--target-host',
metavar='<target_host>',
default=None,
help=_('Name of target host.'))
@cliutils.arg(
'--block-migrate',
action='store_true',
default=False,
help=_('Enable block migration.'))
@cliutils.arg(
'--disk-over-commit',
action='store_true',
default=False,
help=_('Enable disk overcommit.'))
def do_host_evacuate_live(cs, args):
"""Live migrate all instances of the specified host
to other available hosts.

View File

@ -15,6 +15,7 @@
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -36,7 +37,7 @@ def _server_migrate(cs, server):
"error_message": error_message})
@utils.arg('host', metavar='<host>', help='Name of host.')
@cliutils.arg('host', metavar='<host>', help='Name of host.')
def do_host_servers_migrate(cs, args):
"""Migrate all instances of the specified host to other available hosts."""
hypervisors = cs.hypervisors.search(args.host, servers=True)

View File

@ -17,6 +17,7 @@ import pprint
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -40,11 +41,11 @@ class InstanceActionManager(base.ManagerWithFind):
base.getid(server), 'instanceActions')
@utils.arg(
@cliutils.arg(
'server',
metavar='<server>',
help=_('Name or UUID of the server to show an action for.'))
@utils.arg(
@cliutils.arg(
'request_id',
metavar='<request_id>',
help=_('Request ID of the action to get.'))
@ -58,7 +59,7 @@ def do_instance_action(cs, args):
utils.print_dict(action)
@utils.arg(
@cliutils.arg(
'server',
metavar='<server>',
help=_('Name or UUID of the server to list actions for.'))

View File

@ -14,24 +14,26 @@
# under the License.
from novaclient.i18n import _
from novaclient import utils
from novaclient.openstack.common import cliutils
from novaclient.v1_1 import shell
@utils.arg('host',
metavar='<host>',
help=_('Name of host.'))
@utils.arg('action',
metavar='<action>',
choices=['set', 'delete'],
help=_("Actions: 'set' or 'delete'"))
@utils.arg('metadata',
metavar='<key=value>',
nargs='+',
action='append',
default=[],
help=_('Metadata to set or delete (only key is necessary on '
'delete)'))
@cliutils.arg(
'host',
metavar='<host>',
help=_('Name of host.'))
@cliutils.arg(
'action',
metavar='<action>',
choices=['set', 'delete'],
help=_("Actions: 'set' or 'delete'"))
@cliutils.arg(
'metadata',
metavar='<key=value>',
nargs='+',
action='append',
default=[],
help=_('Metadata to set or delete (only key is necessary on delete)'))
def do_host_meta(cs, args):
"""Set or Delete metadata on all instances of a host."""
hypervisors = cs.hypervisors.search(args.host, servers=True)

View File

@ -18,6 +18,7 @@ from six.moves.urllib import parse
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -53,18 +54,21 @@ class MigrationManager(base.ManagerWithFind):
return self._list("/os-migrations%s" % query_string, "migrations")
@utils.arg('--host',
dest='host',
metavar='<host>',
help=_('Fetch migrations for the given host.'))
@utils.arg('--status',
dest='status',
metavar='<status>',
help=_('Fetch migrations for the given status.'))
@utils.arg('--cell_name',
dest='cell_name',
metavar='<cell_name>',
help=_('Fetch migrations for the given cell_name.'))
@cliutils.arg(
'--host',
dest='host',
metavar='<host>',
help=_('Fetch migrations for the given host.'))
@cliutils.arg(
'--status',
dest='status',
metavar='<status>',
help=_('Fetch migrations for the given status.'))
@cliutils.arg(
'--cell_name',
dest='cell_name',
metavar='<cell_name>',
help=_('Fetch migrations for the given cell_name.'))
def do_migration_list(cs, args):
"""Print a list of migrations."""
_print_migrations(cs.migrations.list(args.host, args.status,

View File

@ -14,6 +14,7 @@
from novaclient import base
from novaclient.i18n import _
from novaclient.openstack.common import cliutils
from novaclient import utils
@ -40,7 +41,7 @@ class TenantNetworkManager(base.ManagerWithFind):
return self._create('/os-tenant-networks', body, 'network')
@utils.arg('network_id', metavar='<network_id>', help='ID of network')
@cliutils.arg('network_id', metavar='<network_id>', help='ID of network')
def do_net(cs, args):
"""
Show a network
@ -57,12 +58,14 @@ def do_net_list(cs, args):
utils.print_list(networks, ['ID', 'Label', 'CIDR'])
@utils.arg('label', metavar='<network_label>',
help=_('Network label (ex. my_new_network)'))
@utils.arg(
'cidr', metavar='<cidr>',
help=_('IP block to allocate from (ex. 172.16.0.0/24 or '
'2001:DB8::/64)'))
@cliutils.arg(
'label',
metavar='<network_label>',
help=_('Network label (ex. my_new_network)'))
@cliutils.arg(
'cidr',
metavar='<cidr>',
help=_('IP block to allocate from (ex. 172.16.0.0/24 or 2001:DB8::/64)'))
def do_net_create(cs, args):
"""
Create a network
@ -71,7 +74,7 @@ def do_net_create(cs, args):
utils.print_dict(network._info)
@utils.arg('network_id', metavar='<network_id>', help='ID of network')
@cliutils.arg('network_id', metavar='<network_id>', help='ID of network')
def do_net_delete(cs, args):
"""
Delete a network