Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/deh/list_deh_hosts.py
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions examples/deh/list_deh_servers.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 4 additions & 4 deletions otcextensions/osclient/deh/v1/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions otcextensions/sdk/deh/v1/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions otcextensions/tests/unit/osclient/deh/v1/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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),
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_default_query(self):
limit=1,
marker='some_marker',
name='some_name',
state='available',
status='available',
tenant='all'
)

Expand 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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions otcextensions/tests/unit/sdk/deh/v1/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down