Low-level Compute v2 API: security group · openstack/python-openstackclient@4289ddd · GitHub
Skip to content

Commit 4289ddd

Browse files
author
Dean Troyer
committed
Low-level Compute v2 API: security group
api.compute.APIv2 starts with security group functions. novaclient 8.0 is now released without support for the previously deprecated nova-net functions, so include a new low-level REST implementation of the removed APIs. Change-Id: Id007535f0598226a8202716232313e37fe6247f9
1 parent 09286ad commit 4289ddd

12 files changed

Lines changed: 729 additions & 265 deletions

File tree

openstackclient/api/compute_v2.py

Lines changed: 211 additions & 0 deletions

openstackclient/compute/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"2.1": "novaclient.client",
3232
}
3333

34+
COMPUTE_API_TYPE = 'compute'
35+
COMPUTE_API_VERSIONS = {
36+
'2': 'openstackclient.api.compute_v2.APIv2',
37+
}
38+
3439
# Save the microversion if in use
3540
_compute_api_version = None
3641

@@ -58,6 +63,13 @@ def make_client(instance):
5863

5964
LOG.debug('Instantiating compute client for %s', version)
6065

66+
compute_api = utils.get_client_class(
67+
API_NAME,
68+
version.ver_major,
69+
COMPUTE_API_VERSIONS,
70+
)
71+
LOG.debug('Instantiating compute api: %s', compute_api)
72+
6173
# Set client http_log_debug to True if verbosity level is high enough
6274
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
6375

@@ -77,6 +89,16 @@ def make_client(instance):
7789
**kwargs
7890
)
7991

92+
client.api = compute_api(
93+
session=instance.session,
94+
service_type=COMPUTE_API_TYPE,
95+
endpoint=instance.get_endpoint_for_service_type(
96+
COMPUTE_API_TYPE,
97+
region_name=instance.region_name,
98+
interface=instance.interface,
99+
)
100+
)
101+
80102
return client
81103

82104

openstackclient/compute/v2/server.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@
2222
import os
2323
import sys
2424

25+
from novaclient.v2 import servers
2526
from osc_lib.cli import parseractions
2627
from osc_lib.command import command
2728
from osc_lib import exceptions
2829
from osc_lib import utils
2930
from oslo_utils import timeutils
3031
import six
3132

32-
try:
33-
from novaclient.v2 import servers
34-
except ImportError:
35-
from novaclient.v1_1 import servers
36-
3733
from openstackclient.i18n import _
3834
from openstackclient.identity import common as identity_common
3935

@@ -316,12 +312,11 @@ def take_action(self, parsed_args):
316312
compute_client.servers,
317313
parsed_args.server,
318314
)
319-
security_group = utils.find_resource(
320-
compute_client.security_groups,
315+
security_group = compute_client.api.security_group_find(
321316
parsed_args.group,
322317
)
323318

324-
server.add_security_group(security_group.id)
319+
server.add_security_group(security_group['id'])
325320

326321

327322
class AddServerVolume(command.Command):
@@ -1437,12 +1432,11 @@ def take_action(self, parsed_args):
14371432
compute_client.servers,
14381433
parsed_args.server,
14391434
)
1440-
security_group = utils.find_resource(
1441-
compute_client.security_groups,
1435+
security_group = compute_client.api.security_group_find(
14421436
parsed_args.group,
14431437
)
14441438

1445-
server.remove_security_group(security_group.id)
1439+
server.remove_security_group(security_group['id'])
14461440

14471441

14481442
class RemoveServerVolume(command.Command):

openstackclient/network/v2/security_group.py

Lines changed: 16 additions & 20 deletions

0 commit comments

Comments
 (0)