From 118491f8801ef973dc3af82a3f0c8cc872164fcc Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Wed, 30 Sep 2020 13:12:57 +0000 Subject: [PATCH] change parameter state to status to fit Ansible playbooks --- examples/deh/list_deh_hosts.py | 23 +++++++++++++++++ examples/deh/list_deh_servers.py | 25 +++++++++++++++++++ otcextensions/osclient/deh/v1/host.py | 8 +++--- otcextensions/sdk/deh/v1/host.py | 4 +-- .../tests/unit/osclient/deh/v1/test_host.py | 12 ++++----- .../tests/unit/sdk/deh/v1/test_host.py | 4 +-- 6 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 examples/deh/list_deh_hosts.py create mode 100644 examples/deh/list_deh_servers.py diff --git a/examples/deh/list_deh_hosts.py b/examples/deh/list_deh_hosts.py new file mode 100644 index 000000000..18adb1b2d --- /dev/null +++ b/examples/deh/list_deh_hosts.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +List all allocated Dedicated hosts +""" +import openstack + + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') + +for host in conn.deh.hosts(): + print(host) diff --git a/examples/deh/list_deh_servers.py b/examples/deh/list_deh_servers.py new file mode 100644 index 000000000..a84d08ee0 --- /dev/null +++ b/examples/deh/list_deh_servers.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +List all servers of a Dedicated Host +""" +import openstack + + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') + +host = 'name_or_id' +host = conn.deh.find_host(name_or_id=host) +for server in conn.deh.servers(host=host): + print(server) diff --git a/otcextensions/osclient/deh/v1/host.py b/otcextensions/osclient/deh/v1/host.py index 2975cf08b..ec57059ed 100644 --- a/otcextensions/osclient/deh/v1/host.py +++ b/otcextensions/osclient/deh/v1/host.py @@ -91,11 +91,11 @@ def get_parser(self, prog_name): help=_('Flavor ID.') ) parser.add_argument( - '--state', + '--status', metavar='{' + ','.join(HOST_STATES) + '}', type=lambda s: s.lower(), choices=HOST_STATES, - help=_('Host state filter.') + help=_('Host status filter.') ) parser.add_argument( '--tenant', @@ -142,8 +142,8 @@ def take_action(self, parsed_args): query['host_type_name'] = parsed_args.host_type_name if parsed_args.flavor: query['flavor'] = parsed_args.flavor - if parsed_args.state: - query['state'] = parsed_args.state + if parsed_args.status: + query['status'] = parsed_args.status if parsed_args.tenant: query['tenant'] = parsed_args.tenant if parsed_args.availability_zone: diff --git a/otcextensions/sdk/deh/v1/host.py b/otcextensions/sdk/deh/v1/host.py index be6451ae4..eecedd41d 100644 --- a/otcextensions/sdk/deh/v1/host.py +++ b/otcextensions/sdk/deh/v1/host.py @@ -53,7 +53,7 @@ class Host(resource.Resource): _query_mapping = resource.QueryParameters( 'id', 'name', 'host_type', 'host_type_name', - 'flavor', 'state', 'tenant', 'availability_zone', + 'flavor', 'status', 'tenant', 'availability_zone', 'changes_since', 'tags', 'instance_uuid', 'released_at', changes_since='changes-since') @@ -91,7 +91,7 @@ class Host(resource.Resource): released_at = resource.Body('released_at') #: Specifies the DeH status. #: The value can be available, fault or released - state = resource.Body('state') + status = resource.Body('state') #: Tag. tags = resource.Body('tags', type=list) diff --git a/otcextensions/tests/unit/osclient/deh/v1/test_host.py b/otcextensions/tests/unit/osclient/deh/v1/test_host.py index 868948f44..8f6204dfd 100644 --- a/otcextensions/tests/unit/osclient/deh/v1/test_host.py +++ b/otcextensions/tests/unit/osclient/deh/v1/test_host.py @@ -68,7 +68,7 @@ def test_default_query(self): '--host_type', 'some_type', '--host_type_name', 'some_type_name', '--flavor', 'some_flavor', - '--state', 'available', + '--status', 'available', '--tenant', 'all', '--availability_zone', 'some_az', '--limit', '1', @@ -82,7 +82,7 @@ def test_default_query(self): ('host_type', 'some_type'), ('host_type_name', 'some_type_name'), ('flavor', 'some_flavor'), - ('state', 'available'), + ('status', 'available'), ('tenant', 'all'), ('availability_zone', 'some_az'), ('limit', 1), @@ -111,7 +111,7 @@ def test_default_query(self): limit=1, marker='some_marker', name='some_name', - state='available', + status='available', tenant='all' ) @@ -126,7 +126,7 @@ class TestShowHost(fakes.TestDeH): columns = ( 'allocated_at', 'auto_placement', 'availability_zone', 'available_memory', 'available_vcpus', 'host_properties', 'id', - 'instance_total', 'name', 'project_id', 'released_at', 'state', 'tags' + 'instance_total', 'name', 'project_id', 'released_at', 'status', 'tags' ) data = fakes.gen_data(_data, columns) @@ -268,7 +268,7 @@ class TestSetHost(fakes.TestDeH): columns = ( 'allocated_at', 'auto_placement', 'availability_zone', 'available_memory', 'available_vcpus', 'host_properties', 'id', - 'instance_total', 'name', 'project_id', 'released_at', 'state', 'tags' + 'instance_total', 'name', 'project_id', 'released_at', 'status', 'tags' ) data = fakes.gen_data(_fake, columns) @@ -416,7 +416,7 @@ class TestUnsetHost(fakes.TestDeH): columns = ( 'allocated_at', 'auto_placement', 'availability_zone', 'available_memory', 'available_vcpus', 'host_properties', 'id', - 'instance_total', 'name', 'project_id', 'released_at', 'state', 'tags' + 'instance_total', 'name', 'project_id', 'released_at', 'status', 'tags' ) data = fakes.gen_data(_fake, columns) diff --git a/otcextensions/tests/unit/sdk/deh/v1/test_host.py b/otcextensions/tests/unit/sdk/deh/v1/test_host.py index 537099bb1..f7e57b084 100644 --- a/otcextensions/tests/unit/sdk/deh/v1/test_host.py +++ b/otcextensions/tests/unit/sdk/deh/v1/test_host.py @@ -97,7 +97,7 @@ def test_basic(self): 'marker': 'marker', 'name': 'name', 'released_at': 'released_at', - 'state': 'state', + 'status': 'status', 'tags': 'tags', 'tenant': 'tenant'}, sot._query_mapping._mapping) @@ -115,7 +115,7 @@ def test_make_it(self): self.assertEqual(EXAMPLE['name'], sot.name) self.assertEqual(EXAMPLE['auto_placement'], sot.auto_placement) self.assertEqual(EXAMPLE['availability_zone'], sot.availability_zone) - self.assertEqual(EXAMPLE['state'], sot.state) + self.assertEqual(EXAMPLE['state'], sot.status) self.assertEqual(EXAMPLE['project_id'], sot.project_id) self.assertEqual(EXAMPLE['available_vcpus'], sot.available_vcpus) self.assertEqual(EXAMPLE['available_memory'], sot.available_memory)