4
4
# --- BEGIN_HEADER ---
5
5
#
6
6
# 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
8
8
#
9
9
# This file is part of MiG.
10
10
#
47
47
except ImportError as err :
48
48
requests = None
49
49
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
51
51
from mig .shared .defaults import keyword_all
52
52
from mig .shared .fileio import pickle , unpickle , acquire_file_lock , \
53
53
release_file_lock
@@ -99,7 +99,7 @@ def __wait_available(configuration, client_id, cloud_id, cloud_flavor,
99
99
for i in xrange (__max_wait_secs // __poll_delay_secs ):
100
100
status , msg = status_of_cloud_instance (configuration , client_id ,
101
101
cloud_id , cloud_flavor ,
102
- force_utf8 (instance .name ))
102
+ force_native_str (instance .name ))
103
103
if 'active' == msg .lower ():
104
104
_logger .info ("%s cloud instance %s is ready" % (cloud_id ,
105
105
instance ))
@@ -125,7 +125,7 @@ def __wait_gone(configuration, client_id, cloud_id, cloud_flavor, instance):
125
125
for i in xrange (__max_wait_secs // __poll_delay_secs ):
126
126
status , msg = status_of_cloud_instance (configuration , client_id ,
127
127
cloud_id , cloud_flavor ,
128
- force_utf8 (instance .name ))
128
+ force_native_str (instance .name ))
129
129
if not status :
130
130
_logger .info ("%s cloud instance %s is gone" % (cloud_id ,
131
131
instance ))
@@ -172,8 +172,8 @@ def openstack_list_cloud_images(configuration, client_id, cloud_id):
172
172
return (False , [])
173
173
img_list = []
174
174
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 )
177
177
image_alias = service ['service_image_alias_map' ].get (image_name ,
178
178
image_name )
179
179
img_list .append ((image_name , image_id , image_alias ))
@@ -204,7 +204,7 @@ def openstack_start_cloud_instance(configuration, client_id, cloud_id, instance_
204
204
msg = conn .compute .start_server (instance )
205
205
if msg :
206
206
status = False
207
- msg = force_utf8 (msg )
207
+ msg = force_native_str (msg )
208
208
_logger .error ("%s failed to start %s cloud instance: %s" %
209
209
(client_id , instance_id , msg ))
210
210
else :
@@ -247,7 +247,7 @@ def openstack_stop_cloud_instance(configuration, client_id, cloud_id, instance_i
247
247
msg = conn .compute .stop_server (instance )
248
248
if msg :
249
249
status = False
250
- msg = force_utf8 (msg )
250
+ msg = force_native_str (msg )
251
251
_logger .error ("%s failed to stop %s cloud instance: %s" %
252
252
(client_id , instance_id , msg ))
253
253
else :
@@ -292,7 +292,7 @@ def openstack_restart_cloud_instance(
292
292
msg = conn .compute .reboot_server (instance , boot_strength )
293
293
if msg :
294
294
status = False
295
- msg = force_utf8 (msg )
295
+ msg = force_native_str (msg )
296
296
_logger .error ("%s failed to %s restart %s cloud instance: %s" %
297
297
(client_id , boot_strength , instance_id , msg ))
298
298
else :
@@ -328,7 +328,7 @@ def openstack_status_of_cloud_instance(configuration, client_id, cloud_id,
328
328
try :
329
329
instance = None
330
330
for server in conn .compute .servers ():
331
- if force_utf8 (server .name ) == instance_id :
331
+ if force_native_str (server .name ) == instance_id :
332
332
instance = server
333
333
break
334
334
@@ -340,7 +340,7 @@ def openstack_status_of_cloud_instance(configuration, client_id, cloud_id,
340
340
_logger .error ("%s failed to locate %s cloud instance %s: %s" %
341
341
(client_id , cloud_id , instance_id , msg ))
342
342
return (status , msg )
343
- status_msg = force_utf8 (instance .status )
343
+ status_msg = force_native_str (instance .status )
344
344
if status_msg :
345
345
msg = status_msg
346
346
_logger .info ("%s status for cloud %s instance %s" %
@@ -379,7 +379,7 @@ def openstack_status_all_cloud_instances(configuration, client_id, cloud_id,
379
379
try :
380
380
# Extract corresponding cloud status objects
381
381
for server in conn .compute .servers ():
382
- instance_id = force_utf8 (server .name )
382
+ instance_id = force_native_str (server .name )
383
383
if instance_id in instance_id_list :
384
384
instance_map [instance_id ] = server
385
385
@@ -399,7 +399,7 @@ def openstack_status_all_cloud_instances(configuration, client_id, cloud_id,
399
399
lookup_name = lookup_map .get (name , name )
400
400
raw_val = getattr (instance , lookup_name , "UNKNOWN" )
401
401
if isinstance (raw_val , dict ):
402
- field_val = force_utf8_rec (raw_val )
402
+ field_val = force_native_str_rec (raw_val )
403
403
# NOTE: addresses format is something along the lines of:
404
404
# {NETWORK_ID: [
405
405
# {..., 'addr': INT_IP, 'OS-EXT-IPS:type': 'fixed'},
@@ -426,7 +426,7 @@ def openstack_status_all_cloud_instances(configuration, client_id, cloud_id,
426
426
name )
427
427
field_val = "%s" % field_val
428
428
else :
429
- field_val = force_utf8 (raw_val )
429
+ field_val = force_native_str (raw_val )
430
430
status_dict [instance_id ][name ] = field_val
431
431
status_dict [instance_id ]['success' ] = True
432
432
status_dict [instance_id ]['msg' ] = ''
@@ -457,7 +457,7 @@ def openstack_web_access_cloud_instance(configuration, client_id, cloud_id,
457
457
try :
458
458
instance = None
459
459
for server in conn .compute .servers ():
460
- if force_utf8 (server .name ) == instance_id :
460
+ if force_native_str (server .name ) == instance_id :
461
461
instance = server
462
462
break
463
463
@@ -470,7 +470,7 @@ def openstack_web_access_cloud_instance(configuration, client_id, cloud_id,
470
470
(client_id , cloud_id , instance_id , msg ))
471
471
return (status , msg )
472
472
# 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())
474
474
475
475
web_auth = conn .authorize ()
476
476
@@ -494,7 +494,7 @@ def openstack_web_access_cloud_instance(configuration, client_id, cloud_id,
494
494
(instance_id , server .id , instance ))
495
495
response = requests .post (
496
496
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 ())
498
498
_logger .info ("%s web console response: %s" %
499
499
(client_id , response_dict ))
500
500
console_url = response_dict .get ('console' , {}).get ('url' , '' )
@@ -678,7 +678,7 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
678
678
security_groups = sec_group_id )
679
679
if not instance :
680
680
status = False
681
- msg = force_utf8 ("%s" % instance )
681
+ msg = force_native_str ("%s" % instance )
682
682
_logger .error ("%s failed to create %s cloud instance: %s" %
683
683
(client_id , instance_id , msg ))
684
684
@@ -695,7 +695,7 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
695
695
instance = conn .compute .find_server (instance_id )
696
696
msg = conn .compute .delete_server (instance )
697
697
if msg :
698
- raise Exception (force_utf8 (msg ))
698
+ raise Exception (force_native_str (msg ))
699
699
except Exception as exc :
700
700
_logger .error ("%s failed to clean up %s cloud instance: %s" %
701
701
(client_id , instance_id , exc ))
@@ -706,7 +706,7 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
706
706
floating_network_id = floating_network_id )
707
707
if not floating_ip :
708
708
status = False
709
- msg = force_utf8 ("%s" % floating_ip )
709
+ msg = force_native_str ("%s" % floating_ip )
710
710
_logger .error ("%s failed to create %s cloud instance ip: %s" %
711
711
(client_id , instance_id , msg ))
712
712
return (status , msg )
@@ -716,11 +716,11 @@ def openstack_create_cloud_instance(configuration, client_id, cloud_id,
716
716
instance .id , floating_ip .floating_ip_address )
717
717
if not floating_ip .floating_ip_address :
718
718
status = False
719
- msg = force_utf8 ("%s" % floating_ip .floating_ip_address )
719
+ msg = force_native_str ("%s" % floating_ip .floating_ip_address )
720
720
_logger .error ("%s failed to create %s cloud instance float ip: %s"
721
721
% (client_id , instance_id , msg ))
722
722
return (status , msg )
723
- msg = force_utf8 (floating_ip .floating_ip_address )
723
+ msg = force_native_str (floating_ip .floating_ip_address )
724
724
_logger .info ("%s created cloud %s instance %s with floating IP %s" %
725
725
(client_id , cloud_id , instance_id , msg ))
726
726
@@ -758,7 +758,7 @@ def openstack_delete_cloud_instance(configuration, client_id, cloud_id,
758
758
if instance :
759
759
msg = conn .compute .delete_server (instance )
760
760
if msg :
761
- msg = force_utf8 (msg )
761
+ msg = force_native_str (msg )
762
762
status = False
763
763
_logger .error ("%s failed to delete %s cloud instance: %s" %
764
764
(client_id , instance_id , msg ))
0 commit comments