Skip to content

Commit 209f8e9

Browse files
committed
network: Replace use of in-tree API client
None of these are actually supported by openstacksdk (intentionally so) so we add our own manual implementations. Change-Id: Ifd24f04ae4d1e56e0ce5ba0afe63828403bb7a6f Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 30a6457 commit 209f8e9

18 files changed

Lines changed: 913 additions & 1498 deletions

openstackclient/api/compute_v2.py

Lines changed: 261 additions & 554 deletions
Large diffs are not rendered by default.

openstackclient/compute/client.py

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

34-
COMPUTE_API_TYPE = 'compute'
3534
COMPUTE_API_VERSIONS = {
3635
'2': 'openstackclient.api.compute_v2.APIv2',
3736
}
@@ -63,15 +62,6 @@ def make_client(instance):
6362
# fallback to use the max version of novaclient side.
6463
version = novaclient.API_MAX_VERSION
6564

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

@@ -94,16 +84,6 @@ def make_client(instance):
9484
**kwargs
9585
)
9686

97-
client.api = compute_api(
98-
session=instance.session,
99-
service_type=COMPUTE_API_TYPE,
100-
endpoint=instance.get_endpoint_for_service_type(
101-
COMPUTE_API_TYPE,
102-
region_name=instance.region_name,
103-
interface=instance.interface,
104-
),
105-
)
106-
10787
return client
10888

10989

openstackclient/compute/v2/server.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ def take_action_network(self, client, parsed_args):
552552
raise error
553553

554554
def take_action_compute(self, client, parsed_args):
555-
client.api.floating_ip_add(
556-
parsed_args.server,
555+
server = client.find_server(parsed_args.server, ignore_missing=False)
556+
client.add_floating_ip_to_server(
557+
server,
557558
parsed_args.ip_address,
558559
fixed_address=parsed_args.fixed_ip_address,
559560
)
@@ -3921,10 +3922,8 @@ def take_action_network(self, client, parsed_args):
39213922
client.update_ip(obj, **attrs)
39223923

39233924
def take_action_compute(self, client, parsed_args):
3924-
client.api.floating_ip_remove(
3925-
parsed_args.server,
3926-
parsed_args.ip_address,
3927-
)
3925+
server = client.find_server(parsed_args.server, ignore_missing=False)
3926+
client.remove_floating_ip_from_server(server, parsed_args.ip_address)
39283927

39293928

39303929
class RemovePort(command.Command):

openstackclient/network/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def take_action(self, parsed_args):
161161
)
162162
elif self.is_nova_network:
163163
return self.take_action_compute(
164-
self.app.client_manager.compute, parsed_args
164+
self.app.client_manager.sdk_connection.compute, parsed_args
165165
)
166166

167167
def take_action_network(self, client, parsed_args):
@@ -210,7 +210,8 @@ def take_action(self, parsed_args):
210210
)
211211
else:
212212
self.take_action_compute(
213-
self.app.client_manager.compute, parsed_args
213+
self.app.client_manager.sdk_connection.compute,
214+
parsed_args,
214215
)
215216
except Exception as e:
216217
msg = _(
@@ -267,7 +268,7 @@ def take_action(self, parsed_args):
267268
)
268269
else:
269270
return self.take_action_compute(
270-
self.app.client_manager.compute, parsed_args
271+
self.app.client_manager.sdk_connection.compute, parsed_args
271272
)
272273
except openstack.exceptions.HttpException as exc:
273274
msg = _("Error while executing command: %s") % exc.message

openstackclient/network/v2/floating_ip.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
12-
#
1312

1413
"""IP Floating action implementations"""
1514

1615
from osc_lib import utils
1716
from osc_lib.utils import tags as _tag
1817

18+
from openstackclient.api import compute_v2
1919
from openstackclient.i18n import _
2020
from openstackclient.identity import common as identity_common
2121
from openstackclient.network import common
2222

23-
2423
_formatters = {
2524
'port_details': utils.format_dict,
2625
}
@@ -200,7 +199,7 @@ def take_action_network(self, client, parsed_args):
200199
return (display_columns, data)
201200

202201
def take_action_compute(self, client, parsed_args):
203-
obj = client.api.floating_ip_create(parsed_args.network)
202+
obj = compute_v2.create_floating_ip(client, parsed_args.network)
204203
columns = _get_columns(obj)
205204
data = utils.get_dict_properties(obj, columns)
206205
return (columns, data)
@@ -230,7 +229,7 @@ def take_action_network(self, client, parsed_args):
230229
client.delete_ip(obj)
231230

232231
def take_action_compute(self, client, parsed_args):
233-
client.api.floating_ip_delete(self.r)
232+
compute_v2.delete_floating_ip(client, self.r)
234233

235234

236235
class ListFloatingIP(common.NetworkAndComputeLister):
@@ -421,8 +420,7 @@ def take_action_compute(self, client, parsed_args):
421420
'Pool',
422421
)
423422

424-
data = client.api.floating_ip_list()
425-
423+
objs = compute_v2.list_floating_ips(client)
426424
return (
427425
headers,
428426
(
@@ -431,7 +429,7 @@ def take_action_compute(self, client, parsed_args):
431429
columns,
432430
formatters={},
433431
)
434-
for s in data
432+
for s in objs
435433
),
436434
)
437435

@@ -538,7 +536,7 @@ def take_action_network(self, client, parsed_args):
538536
return (display_columns, data)
539537

540538
def take_action_compute(self, client, parsed_args):
541-
obj = client.api.floating_ip_find(parsed_args.floating_ip)
539+
obj = compute_v2.get_floating_ip(client, parsed_args.floating_ip)
542540
columns = _get_columns(obj)
543541
data = utils.get_dict_properties(obj, columns)
544542
return (columns, data)

openstackclient/network/v2/floating_ip_pool.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
12-
#
1312

1413
"""Floating IP Pool action implementations"""
1514

16-
1715
from osc_lib import exceptions
18-
from osc_lib import utils
1916

17+
from openstackclient.api import compute_v2
2018
from openstackclient.i18n import _
2119
from openstackclient.network import common
2220

@@ -33,15 +31,8 @@ def take_action_network(self, client, parsed_args):
3331

3432
def take_action_compute(self, client, parsed_args):
3533
columns = ('Name',)
36-
data = client.api.floating_ip_pool_list()
37-
38-
return (
39-
columns,
40-
(
41-
utils.get_dict_properties(
42-
s,
43-
columns,
44-
)
45-
for s in data
46-
),
47-
)
34+
data = [
35+
(x['name'],) for x in compute_v2.list_floating_ip_pools(client)
36+
]
37+
38+
return (columns, data)

openstackclient/network/v2/network.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
12-
#
1312

1413
"""Network action implementations"""
1514

@@ -18,6 +17,7 @@
1817
from osc_lib import utils
1918
from osc_lib.utils import tags as _tag
2019

20+
from openstackclient.api import compute_v2
2121
from openstackclient.i18n import _
2222
from openstackclient.identity import common as identity_common
2323
from openstackclient.network import common
@@ -388,7 +388,7 @@ def take_action_network(self, client, parsed_args):
388388

389389
def take_action_compute(self, client, parsed_args):
390390
attrs = _get_attrs_compute(self.app.client_manager, parsed_args)
391-
obj = client.api.network_create(**attrs)
391+
obj = compute_v2.create_network(client, **attrs)
392392
display_columns, columns = _get_columns_compute(obj)
393393
data = utils.get_dict_properties(obj, columns)
394394
return (display_columns, data)
@@ -416,7 +416,8 @@ def take_action_network(self, client, parsed_args):
416416
client.delete_network(obj)
417417

418418
def take_action_compute(self, client, parsed_args):
419-
client.api.network_delete(self.r)
419+
network = compute_v2.find_network(client, self.r)
420+
compute_v2.delete_network(client, network['id'])
420421

421422

422423
# TODO(sindhu): Use the SDK resource mapped attribute names once the
@@ -673,7 +674,7 @@ def take_action_compute(self, client, parsed_args):
673674
'Subnet',
674675
)
675676

676-
data = client.api.network_list()
677+
data = compute_v2.list_networks(client)
677678

678679
return (
679680
column_headers,
@@ -828,7 +829,7 @@ def take_action_network(self, client, parsed_args):
828829
return (display_columns, data)
829830

830831
def take_action_compute(self, client, parsed_args):
831-
obj = client.api.network_find(parsed_args.network)
832+
obj = compute_v2.find_network(client, parsed_args.network)
832833
display_columns, columns = _get_columns_compute(obj)
833834
data = utils.get_dict_properties(obj, columns)
834835
return (display_columns, data)

openstackclient/network/v2/security_group.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from osc_lib import utils
2121
from osc_lib.utils import tags as _tag
2222

23+
from openstackclient.api import compute_v2
2324
from openstackclient.i18n import _
2425
from openstackclient.identity import common as identity_common
2526
from openstackclient.network import common
@@ -180,7 +181,8 @@ def take_action_network(self, client, parsed_args):
180181

181182
def take_action_compute(self, client, parsed_args):
182183
description = self._get_description(parsed_args)
183-
obj = client.api.security_group_create(
184+
obj = compute_v2.create_security_group(
185+
client,
184186
parsed_args.name,
185187
description,
186188
)
@@ -212,7 +214,8 @@ def take_action_network(self, client, parsed_args):
212214
client.delete_security_group(obj)
213215

214216
def take_action_compute(self, client, parsed_args):
215-
client.api.security_group_delete(self.r)
217+
security_group = compute_v2.find_security_group(client, self.r)
218+
compute_v2.delete_security_group(client, security_group['id'])
216219

217220

218221
# TODO(rauta): Use the SDK resource mapped attribute names once
@@ -291,10 +294,10 @@ def take_action_network(self, client, parsed_args):
291294
)
292295

293296
def take_action_compute(self, client, parsed_args):
294-
search = {'all_tenants': parsed_args.all_projects}
295-
data = client.api.security_group_list(
297+
data = compute_v2.list_security_groups(
296298
# TODO(dtroyer): add limit, marker
297-
search_opts=search,
299+
client,
300+
all_projects=parsed_args.all_projects,
298301
)
299302

300303
columns = (
@@ -383,20 +386,21 @@ def take_action_network(self, client, parsed_args):
383386
_tag.update_tags_for_set(client, obj, parsed_args)
384387

385388
def take_action_compute(self, client, parsed_args):
386-
data = client.api.security_group_find(parsed_args.group)
389+
security_group = compute_v2.find_security_group(
390+
client, parsed_args.group
391+
)
387392

393+
params = {}
388394
if parsed_args.name is not None:
389-
data['name'] = parsed_args.name
395+
params['name'] = parsed_args.name
390396
if parsed_args.description is not None:
391-
data['description'] = parsed_args.description
397+
params['description'] = parsed_args.description
392398

393399
# NOTE(rtheis): Previous behavior did not raise a CommandError
394400
# if there were no updates. Maintain this behavior and issue
395401
# the update.
396-
client.api.security_group_set(
397-
data,
398-
data['name'],
399-
data['description'],
402+
compute_v2.update_security_group(
403+
client, security_group['id'], **params
400404
)
401405

402406

@@ -422,7 +426,7 @@ def take_action_network(self, client, parsed_args):
422426
return (display_columns, data)
423427

424428
def take_action_compute(self, client, parsed_args):
425-
obj = client.api.security_group_find(parsed_args.group)
429+
obj = compute_v2.find_security_group(client, parsed_args.group)
426430
display_columns, property_columns = _get_columns(obj)
427431
data = utils.get_dict_properties(
428432
obj, property_columns, formatters=_formatters_compute

0 commit comments

Comments
 (0)