25
25
from oci_utils .migrate import system_tools
26
26
from oci_utils .migrate import terminal_dimension
27
27
from oci_utils .migrate .exception import OciMigrateException
28
- from oci_utils .migrate .migrate_tools import get_config_data as get_config_data
28
+ from oci_utils .migrate .migrate_tools import get_config_data
29
29
30
- if sys .version_info .major < 3 :
31
- exit_with_msg ('Python version 3 is a requirement to run this utility.' )
32
-
33
- _logger = logging .getLogger ('oci-utils.import_ci' )
30
+ _logger = logging .getLogger ('oci-utils.oci-image-import' )
34
31
35
32
36
33
def parse_args ():
@@ -107,11 +104,18 @@ def parse_args():
107
104
108
105
109
106
def main ():
107
+ """
108
+ Import image from object storage into custom images repository.
109
+
110
+ Returns
111
+ -------
112
+ int: 0 on success, raises exception on failure.
113
+ """
110
114
#
111
115
# set locale
112
116
lc_all_to_set = get_config_data ('lc_all' )
113
117
os .environ ['LC_ALL' ] = "%s" % lc_all_to_set
114
- _logger .debug ('Locale set to %s' % lc_all_to_set )
118
+ _logger .debug ('Locale set to %s' , lc_all_to_set )
115
119
#
116
120
# command line
117
121
cmdline_args = parse_args ()
@@ -138,7 +142,7 @@ def main():
138
142
#
139
143
# compartment data for tenancy
140
144
tenancy = oci_config ['tenancy' ]
141
- _logger .debug ('Tenancy: %s' % tenancy )
145
+ _logger .debug ('Tenancy: %s' , tenancy )
142
146
compartment_dict = oci_cli_tools .get_tenancy_data (tenancy )
143
147
#
144
148
# object storage namespace
@@ -155,18 +159,16 @@ def main():
155
159
#
156
160
# object present in object storage
157
161
if oci_cli_tools .object_exists (object_storage_data , object_name ):
158
- _logger .debug ('Object %s present in object_storage %s'
159
- % (object_name , bucket ))
162
+ _logger .debug ('Object %s present in object_storage %s' , object_name , bucket )
160
163
else :
161
164
raise OciMigrateException ('Object %s does not exist in the object '
162
165
'storage %s.' % (object_name , bucket ))
163
166
#
164
- # display namee present
167
+ # display name present
165
168
if oci_cli_tools .display_name_exists (display_name , compartment_id ):
166
169
raise OciMigrateException ('Image with name %s already exists.'
167
170
% display_name )
168
- else :
169
- _logger .debug ('%s does not exist' % display_name )
171
+ _logger .debug ('%s does not exist' , display_name )
170
172
except Exception as e :
171
173
exit_with_msg ('Error while importing %s data: %s' % (object_name , str (e )))
172
174
#
@@ -190,21 +192,19 @@ def main():
190
192
#
191
193
# Follow up the import.
192
194
finished = False
193
- _ , nbcols = terminal_dimension ()
194
- importwait = ProgressBar (nbcols , 0.2 ,
195
- progress_chars = ['importing %s' % display_name ])
196
- importwait .start ()
195
+ _ , nb_columns = terminal_dimension ()
196
+ import_progress = ProgressBar (nb_columns , 0.2 , progress_chars = ['importing %s' % display_name ])
197
+ import_progress .start ()
197
198
try :
198
199
while not finished :
199
200
if oci_cli_tools .get_lifecycle_state (display_name , compartment_id ) \
200
201
== 'AVAILABLE' :
201
202
finished = True
202
203
except Exception as e :
203
- _logger .error ('Failed to follow up on the import of %s, giving up: %s'
204
- % (display_name , str (e )))
204
+ _logger .error ('Failed to follow up on the import of %s, giving up: %s' , display_name , str (e ))
205
205
206
- if system_tools .is_thread_running (importwait ):
207
- importwait .stop ()
206
+ if system_tools .is_thread_running (import_progress ):
207
+ import_progress .stop ()
208
208
console_msg (msg = 'Done' )
209
209
return 0
210
210
0 commit comments