diff --git a/novaclient/client.py b/novaclient/client.py index be31686a3..a04a92e47 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -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): diff --git a/novaclient/shell.py b/novaclient/shell.py index bb79d6379..b2a2203fd 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -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='', - 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='', - 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='', - 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='', - 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='', - 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='', - 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='', 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='', - 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='', 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='', nargs='?', diff --git a/novaclient/utils.py b/novaclient/utils.py index e82a8ac5a..fbc5da604 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -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) diff --git a/novaclient/v1_1/contrib/baremetal.py b/novaclient/v1_1/contrib/baremetal.py index 325e27211..d23a38e53 100644 --- a/novaclient/v1_1/contrib/baremetal.py +++ b/novaclient/v1_1/contrib/baremetal.py @@ -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='', help=_('Name of nova compute host which will control this baremetal ' 'node')) -@utils.arg( +@cliutils.arg( 'cpus', metavar='', type=int, help=_('Number of CPUs in the node')) -@utils.arg( +@cliutils.arg( 'memory_mb', metavar='', type=int, help=_('Megabytes of RAM in the node')) -@utils.arg( +@cliutils.arg( 'local_gb', metavar='', type=int, help=_('Gigabytes of local storage in the node')) -@utils.arg( +@cliutils.arg( 'prov_mac_address', metavar='', help=_('MAC address to provision the node')) -@utils.arg( +@cliutils.arg( '--pm_address', default=None, metavar='', help=_('Power management IP for the node')) -@utils.arg( +@cliutils.arg( '--pm_user', default=None, metavar='', help=_('Username for the node\'s power management')) -@utils.arg( +@cliutils.arg( '--pm_password', default=None, metavar='', help=_('Password for the node\'s power management')) -@utils.arg( +@cliutils.arg( '--terminal_port', default=None, metavar='', type=int, @@ -204,7 +205,7 @@ def do_baremetal_node_create(cs, args): _print_baremetal_resource(node) -@utils.arg( +@cliutils.arg( 'node', metavar='', help=_('ID of the node to delete.')) @@ -286,7 +287,7 @@ def _print_baremetal_node_interfaces(interfaces): ]) -@utils.arg( +@cliutils.arg( 'node', metavar='', 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='', help=_("ID of node")) -@utils.arg( +@cliutils.arg( 'address', metavar='
', help=_("MAC address of interface")) -@utils.arg( +@cliutils.arg( '--datapath_id', default=0, metavar='', help=_("OpenFlow Datapath ID of interface")) -@utils.arg( +@cliutils.arg( '--port_no', default=0, metavar='', @@ -321,14 +322,17 @@ def do_baremetal_interface_add(cs, args): _print_baremetal_resource(bmif) -@utils.arg('node', metavar='', help=_("ID of node")) -@utils.arg('address', metavar='
', help=_("MAC address of interface")) +@cliutils.arg('node', metavar='', help=_("ID of node")) +@cliutils.arg( + 'address', + metavar='
', + 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='', help=_("ID of node")) +@cliutils.arg('node', metavar='', 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) diff --git a/novaclient/v1_1/contrib/cells.py b/novaclient/v1_1/contrib/cells.py index 464ec8e15..bfc6893d7 100644 --- a/novaclient/v1_1/contrib/cells.py +++ b/novaclient/v1_1/contrib/cells.py @@ -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='', 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='', help=_("Name of the cell to get the capacities."), diff --git a/novaclient/v1_1/contrib/deferred_delete.py b/novaclient/v1_1/contrib/deferred_delete.py index 1412702d5..5d8d7d9e3 100644 --- a/novaclient/v1_1/contrib/deferred_delete.py +++ b/novaclient/v1_1/contrib/deferred_delete.py @@ -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='', help='Name or ID of server.') +@cliutils.arg('server', metavar='', 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='', help='Name or ID of server.') +@cliutils.arg('server', metavar='', help='Name or ID of server.') def do_restore(cs, args): """Restore a soft-deleted server.""" utils.find_resource(cs.servers, args.server).restore() diff --git a/novaclient/v1_1/contrib/host_evacuate.py b/novaclient/v1_1/contrib/host_evacuate.py index e935e23db..b08e28cd1 100644 --- a/novaclient/v1_1/contrib/host_evacuate.py +++ b/novaclient/v1_1/contrib/host_evacuate.py @@ -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='', help='Name of host.') -@utils.arg('--target_host', - metavar='', - 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='', help='Name of host.') +@cliutils.arg( + '--target_host', + metavar='', + 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) diff --git a/novaclient/v1_1/contrib/host_evacuate_live.py b/novaclient/v1_1/contrib/host_evacuate_live.py index 0f6a59673..276fb2f70 100644 --- a/novaclient/v1_1/contrib/host_evacuate_live.py +++ b/novaclient/v1_1/contrib/host_evacuate_live.py @@ -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='', help='Name of host.') -@utils.arg('--target-host', - metavar='', - 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='', help='Name of host.') +@cliutils.arg( + '--target-host', + metavar='', + 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. diff --git a/novaclient/v1_1/contrib/host_servers_migrate.py b/novaclient/v1_1/contrib/host_servers_migrate.py index 95268186b..470f161f1 100644 --- a/novaclient/v1_1/contrib/host_servers_migrate.py +++ b/novaclient/v1_1/contrib/host_servers_migrate.py @@ -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='', help='Name of host.') +@cliutils.arg('host', metavar='', 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) diff --git a/novaclient/v1_1/contrib/instance_action.py b/novaclient/v1_1/contrib/instance_action.py index 2f20e0611..10e518ea2 100644 --- a/novaclient/v1_1/contrib/instance_action.py +++ b/novaclient/v1_1/contrib/instance_action.py @@ -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='', help=_('Name or UUID of the server to show an action for.')) -@utils.arg( +@cliutils.arg( 'request_id', metavar='', 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='', help=_('Name or UUID of the server to list actions for.')) diff --git a/novaclient/v1_1/contrib/metadata_extensions.py b/novaclient/v1_1/contrib/metadata_extensions.py index 54bf8fd04..36bef9abb 100644 --- a/novaclient/v1_1/contrib/metadata_extensions.py +++ b/novaclient/v1_1/contrib/metadata_extensions.py @@ -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='', - help=_('Name of host.')) -@utils.arg('action', - metavar='', - choices=['set', 'delete'], - help=_("Actions: 'set' or 'delete'")) -@utils.arg('metadata', - metavar='', - nargs='+', - action='append', - default=[], - help=_('Metadata to set or delete (only key is necessary on ' - 'delete)')) +@cliutils.arg( + 'host', + metavar='', + help=_('Name of host.')) +@cliutils.arg( + 'action', + metavar='', + choices=['set', 'delete'], + help=_("Actions: 'set' or 'delete'")) +@cliutils.arg( + 'metadata', + metavar='', + 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) diff --git a/novaclient/v1_1/contrib/migrations.py b/novaclient/v1_1/contrib/migrations.py index c10fb3519..15959818a 100644 --- a/novaclient/v1_1/contrib/migrations.py +++ b/novaclient/v1_1/contrib/migrations.py @@ -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='', - help=_('Fetch migrations for the given host.')) -@utils.arg('--status', - dest='status', - metavar='', - help=_('Fetch migrations for the given status.')) -@utils.arg('--cell_name', - dest='cell_name', - metavar='', - help=_('Fetch migrations for the given cell_name.')) +@cliutils.arg( + '--host', + dest='host', + metavar='', + help=_('Fetch migrations for the given host.')) +@cliutils.arg( + '--status', + dest='status', + metavar='', + help=_('Fetch migrations for the given status.')) +@cliutils.arg( + '--cell_name', + dest='cell_name', + metavar='', + 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, diff --git a/novaclient/v1_1/contrib/tenant_networks.py b/novaclient/v1_1/contrib/tenant_networks.py index 3bd2547d4..06edeb145 100644 --- a/novaclient/v1_1/contrib/tenant_networks.py +++ b/novaclient/v1_1/contrib/tenant_networks.py @@ -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='', help='ID of network') +@cliutils.arg('network_id', metavar='', 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='', - help=_('Network label (ex. my_new_network)')) -@utils.arg( - 'cidr', metavar='', - help=_('IP block to allocate from (ex. 172.16.0.0/24 or ' - '2001:DB8::/64)')) +@cliutils.arg( + 'label', + metavar='', + help=_('Network label (ex. my_new_network)')) +@cliutils.arg( + 'cidr', + metavar='', + 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='', help='ID of network') +@cliutils.arg('network_id', metavar='', help='ID of network') def do_net_delete(cs, args): """ Delete a network