Skip to content

Commit 489c12f

Browse files
committed
Merge remote-tracking branch 'origin/master' into edge
2 parents 456aada + a5459ca commit 489c12f

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

mig/shared/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,14 @@ def _force_default_coding_rec(input_obj, kind, highlight=''):
615615
raise ValueError('Unsupported default coding kind: %s' % kind)
616616

617617

618+
def force_native_str_rec(input_obj, highlight=''):
619+
"""A helper to force input_obj to the default string coding.
620+
Use the active interpreter and the shared.defaults helpers to force the
621+
current default.
622+
"""
623+
return _force_default_coding_rec(input_obj, STR_KIND, highlight)
624+
625+
618626
def force_default_str_coding_rec(input_obj, highlight=''):
619627
"""A helper to force input_obj to the default string coding recursively.
620628
Use the active interpreter and the shared.defaults helpers to force the

mig/shared/cloud.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# cloud - Helper functions for the cloud service
7-
# Copyright (C) 2003-2023 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -47,7 +47,7 @@
4747
except ImportError as err:
4848
requests = None
4949

50-
from mig.shared.base import force_utf8, force_utf8_rec, client_id_dir
50+
from mig.shared.base import force_native_str, force_native_str_rec, client_id_dir
5151
from mig.shared.defaults import keyword_all
5252
from mig.shared.fileio import pickle, unpickle, acquire_file_lock, \
5353
release_file_lock
@@ -99,7 +99,7 @@ def __wait_available(configuration, client_id, cloud_id, cloud_flavor,
9999
for i in xrange(__max_wait_secs // __poll_delay_secs):
100100
status, msg = status_of_cloud_instance(configuration, client_id,
101101
cloud_id, cloud_flavor,
102-
force_utf8(instance.name))
102+
force_native_str(instance.name))
103103
if 'active' == msg.lower():
104104
_logger.info("%s cloud instance %s is ready" % (cloud_id,
105105
instance))
@@ -125,7 +125,7 @@ def __wait_gone(configuration, client_id, cloud_id, cloud_flavor, instance):
125125
for i in xrange(__max_wait_secs // __poll_delay_secs):
126126
status, msg = status_of_cloud_instance(configuration, client_id,
127127
cloud_id, cloud_flavor,
128-
force_utf8(instance.name))
128+
force_native_str(instance.name))
129129
if not status:
130130
_logger.info("%s cloud instance %s is gone" % (cloud_id,
131131
instance))
@@ -172,8 +172,8 @@ def openstack_list_cloud_images(configuration, client_id, cloud_id):
172172
return (False, [])
173173
img_list = []
174174
for image in conn.image.images():
175-
image_name = force_utf8(image.name)
176-
image_id = force_utf8(image.id)
175+
image_name = force_native_str(image.name)
176+
image_id = force_native_str(image.id)
177177
image_alias = service['service_image_alias_map'].get(image_name,
178178
image_name)
179179
img_list.append((image_name, image_id, image_alias))
@@ -204,7 +204,7 @@ def openstack_start_cloud_instance(configuration, client_id, cloud_id, instance_
204204
msg = conn.compute.start_server(instance)
205205
if msg:
206206
status = False
207-
msg = force_utf8(msg)
207+
msg = force_native_str(msg)
208208
_logger.error("%s failed to start %s cloud instance: %s" %
209209
(client_id, instance_id, msg))
210210
else:
@@ -247,7 +247,7 @@ def openstack_stop_cloud_instance(configuration, client_id, cloud_id, instance_i
247247
msg = conn.compute.stop_server(instance)
248248
if msg:
249249
status = False
250-
msg = force_utf8(msg)
250+
msg = force_native_str(msg)
251251
_logger.error("%s failed to stop %s cloud instance: %s" %
252252
(client_id, instance_id, msg))
253253
else:
@@ -292,7 +292,7 @@ def openstack_restart_cloud_instance(
292292
msg = conn.compute.reboot_server(instance, boot_strength)
293293
if msg:
294294
status = False
295-
msg = force_utf8(msg)
295+
msg = force_native_str(msg)
296296
_logger.error("%s failed to %s restart %s cloud instance: %s" %
297297
(client_id, boot_strength, instance_id, msg))
298298
else:
@@ -328,7 +328,7 @@ def openstack_status_of_cloud_instance(configuration, client_id, cloud_id,
328328
try:
329329
instance = None
330330
for server in conn.compute.servers():
331-
if force_utf8(server.name) == instance_id:
331+
if force_native_str(server.name) == instance_id:
332332
instance = server
333333
break
334334

@@ -340,7 +340,7 @@ def openstack_status_of_cloud_instance(configuration, client_id, cloud_id,
340340
_logger.error("%s failed to locate %s cloud instance %s: %s" %
341341
(client_id, cloud_id, instance_id, msg))
342342
return (status, msg)
343-
status_msg = force_utf8(instance.status)
343+
status_msg = force_native_str(instance.status)
344344
if status_msg:
345345
msg = status_msg
346346
_logger.info("%s status for cloud %s instance %s" %
@@ -379,7 +379,7 @@ def openstack_status_all_cloud_instances(configuration, client_id, cloud_id,
379379
try:
380380
# Extract corresponding cloud status objects
381381
for server in conn.compute.servers():
382-
instance_id = force_utf8(server.name)
382+
instance_id = force_native_str(server.name)
383383
if instance_id in instance_id_list:
384384
instance_map[instance_id] = server
385385

@@ -399,7 +399,7 @@ def openstack_status_all_cloud_instances(configuration, client_id, cloud_id,
399399
lookup_name = lookup_map.get(name, name)
400400
raw_val = getattr(instance, lookup_name, "UNKNOWN")
401401
if isinstance(raw_val, dict):
402-
field_val = force_utf8_rec(raw_val)
402+
field_val = force_native_str_rec(raw_val)
403403
# NOTE: addresses format is something along the lines of:
404404
# {NETWORK_ID: [
405405
# {..., 'addr': INT_IP, 'OS-EXT-IPS:type': 'fixed'},
@@ -426,7 +426,7 @@ def openstack_status_all_cloud_instances(configuration, client_id, cloud_id,
426426
name)
427427
field_val = "%s" % field_val
428428
else:
429-
field_val = force_utf8(raw_val)
429+
field_val = force_native_str(raw_val)
430430
status_dict[instance_id][name] = field_val
431431
status_dict[instance_id]['success'] = True
432432
status_dict[instance_id]['msg'] = ''
@@ -457,7 +457,7 @@ def openstack_web_access_cloud_instance(configuration, client_id, cloud_id,
457457
try:
458458
instance = None
459459
for server in conn.compute.servers():
460-
if force_utf8(server.name) == instance_id:
460+
if force_native_str(server.name) == instance_id:
461461
instance = server
462462
break
463463

@@ -470,7 +470,7 @@ def openstack_web_access_cloud_instance(configuration, client_id, cloud_id,
470470
(client_id, cloud_id, instance_id, msg))
471471
return (status, msg)
472472
# TODO: openstack does not expose console URL - manual request for now
473-
# console_url = force_utf8(instance.get_console_url())
473+
# console_url = force_native_str(instance.get_console_url())
474474

475475
web_auth = conn.authorize()
476476

@@ -494,7 +494,7 @@ def openstack_web_access_cloud_instance(configuration, client_id, cloud_id,
494494
(instance_id, server.id, instance))
495495
response = requests.post(
496496
API_ENDPOINT, headers=HEADERS, data=body, verify=True)
497-
response_dict = force_utf8_rec(response.json())
497+
response_dict = force_native_str_rec(response.json())
498498
_logger.info("%s web console response: %s" %
499499
(client_id, response_dict))
500500
console_url = response_dict.get('console', {}).get('url', '')
@@ -678,7 +678,7 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
678678
security_groups=sec_group_id)
679679
if not instance:
680680
status = False
681-
msg = force_utf8("%s" % instance)
681+
msg = force_native_str("%s" % instance)
682682
_logger.error("%s failed to create %s cloud instance: %s" %
683683
(client_id, instance_id, msg))
684684

@@ -695,7 +695,7 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
695695
instance = conn.compute.find_server(instance_id)
696696
msg = conn.compute.delete_server(instance)
697697
if msg:
698-
raise Exception(force_utf8(msg))
698+
raise Exception(force_native_str(msg))
699699
except Exception as exc:
700700
_logger.error("%s failed to clean up %s cloud instance: %s" %
701701
(client_id, instance_id, exc))
@@ -706,7 +706,7 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
706706
floating_network_id=floating_network_id)
707707
if not floating_ip:
708708
status = False
709-
msg = force_utf8("%s" % floating_ip)
709+
msg = force_native_str("%s" % floating_ip)
710710
_logger.error("%s failed to create %s cloud instance ip: %s" %
711711
(client_id, instance_id, msg))
712712
return (status, msg)
@@ -716,11 +716,11 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
716716
instance.id, floating_ip.floating_ip_address)
717717
if not floating_ip.floating_ip_address:
718718
status = False
719-
msg = force_utf8("%s" % floating_ip.floating_ip_address)
719+
msg = force_native_str("%s" % floating_ip.floating_ip_address)
720720
_logger.error("%s failed to create %s cloud instance float ip: %s"
721721
% (client_id, instance_id, msg))
722722
return (status, msg)
723-
msg = force_utf8(floating_ip.floating_ip_address)
723+
msg = force_native_str(floating_ip.floating_ip_address)
724724
_logger.info("%s created cloud %s instance %s with floating IP %s" %
725725
(client_id, cloud_id, instance_id, msg))
726726

@@ -758,7 +758,7 @@ def openstack_delete_cloud_instance(configuration, client_id, cloud_id,
758758
if instance:
759759
msg = conn.compute.delete_server(instance)
760760
if msg:
761-
msg = force_utf8(msg)
761+
msg = force_native_str(msg)
762762
status = False
763763
_logger.error("%s failed to delete %s cloud instance: %s" %
764764
(client_id, instance_id, msg))

0 commit comments

Comments
 (0)