Skip to content

Commit 30a6457

Browse files
committed
compute: Migrate 'server create' to SDK
The final step. Future changes will clean up the remnants of the novaclient usage. This is a rather large patch, owing to the number of things that novaclient was handling for us which SDK does not, but the combination of unit and functional tests mean we should be handling all of these differences. Change-Id: I623e8c772235438a3d1590e1bbd832748d6e62ea Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent d22f264 commit 30a6457

5 files changed

Lines changed: 1530 additions & 1451 deletions

File tree

openstackclient/api/compute_v2.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,40 @@ def find_security_group(compute_client, name_or_id):
621621
raise exceptions.NotFound(f'{name_or_id} not found')
622622

623623
return found
624+
625+
626+
def find_network(compute_client, name_or_id):
627+
"""Find the ID for a given network name or ID
628+
629+
https://docs.openstack.org/api-ref/compute/#show-network-details
630+
631+
:param compute_client: A compute client
632+
:param name_or_id: The name or ID of the network to look up
633+
:returns: A network object
634+
:raises exception.NotFound: If a matching network could not be found or
635+
more than one match was found
636+
"""
637+
response = compute_client.get(
638+
f'/os-networks/{name_or_id}', microversion='2.1'
639+
)
640+
if response.status_code != http.HTTPStatus.NOT_FOUND:
641+
# there might be other, non-404 errors
642+
sdk_exceptions.raise_from_response(response)
643+
return response.json()['network']
644+
645+
response = compute_client.get('/os-networks', microversion='2.1')
646+
sdk_exceptions.raise_from_response(response)
647+
found = None
648+
networks = response.json()['networks']
649+
for network in networks:
650+
if network['label'] == name_or_id:
651+
if found:
652+
raise exceptions.NotFound(
653+
f'multiple matches found for {name_or_id}'
654+
)
655+
found = network
656+
657+
if not found:
658+
raise exceptions.NotFound(f'{name_or_id} not found')
659+
660+
return found

0 commit comments

Comments
 (0)