Skip to content

Commit 3d4ecd5

Browse files
Merge pull request #110 from guidotijskens/migrate20201009
cleanup
2 parents 31fcea4 + e4e25e5 commit 3d4ecd5

22 files changed

+1351
-1658
lines changed

buildrpm/oci-utils.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: oci-utils
2-
Version: 0.11.6
2+
Version: 0.11.7
33
Release: 6%{?dist}
44
Url: http://cloud.oracle.com/iaas
55
Summary: Oracle Cloud Infrastructure utilities
@@ -176,6 +176,9 @@ rm -rf %{buildroot}
176176
/opt/oci-utils/tests/__init__*
177177

178178
%changelog
179+
* Fri Oct 9 2020 Guido Tijskens <[email protected]> --0.11.6-1
180+
- oci-image-migrate code cleanup
181+
179182
* Thu Sep 24 2020 Emmanuel Jannetti <[email protected]> --0.11.6
180183
- LINUX-7035 - oci-utils: move base functionality from al-config to oci-utils
181184
- LINUX-8976 - multi-vnic on bare metal shapes suffer from connection issues

data/oci-migrate-conf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ lc_all: en_US.utf8
1919
# logfilepath : /var/tmp/oci-image-migrate
2020
#
2121
# result file path without extension, image references are added runtime,
22-
resultfilepath : /var/tmp/oci-image-migrate
22+
result_filepath : /var/tmp/oci-image-migrate
2323
#
2424
# Dictionary containing utilities which might be needed with the packages
2525
# which provide them.

lib/oci_utils/impl/migrate/oci-image-migrate-import-main.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525
from oci_utils.migrate import system_tools
2626
from oci_utils.migrate import terminal_dimension
2727
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
2929

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')
3431

3532

3633
def parse_args():
@@ -107,11 +104,18 @@ def parse_args():
107104

108105

109106
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+
"""
110114
#
111115
# set locale
112116
lc_all_to_set = get_config_data('lc_all')
113117
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)
115119
#
116120
# command line
117121
cmdline_args = parse_args()
@@ -138,7 +142,7 @@ def main():
138142
#
139143
# compartment data for tenancy
140144
tenancy = oci_config['tenancy']
141-
_logger.debug('Tenancy: %s' % tenancy)
145+
_logger.debug('Tenancy: %s', tenancy)
142146
compartment_dict = oci_cli_tools.get_tenancy_data(tenancy)
143147
#
144148
# object storage namespace
@@ -155,18 +159,16 @@ def main():
155159
#
156160
# object present in object storage
157161
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)
160163
else:
161164
raise OciMigrateException('Object %s does not exist in the object '
162165
'storage %s.' % (object_name, bucket))
163166
#
164-
# display namee present
167+
# display name present
165168
if oci_cli_tools.display_name_exists(display_name, compartment_id):
166169
raise OciMigrateException('Image with name %s already exists.'
167170
% display_name)
168-
else:
169-
_logger.debug('%s does not exist' % display_name)
171+
_logger.debug('%s does not exist', display_name)
170172
except Exception as e:
171173
exit_with_msg('Error while importing %s data: %s' % (object_name, str(e)))
172174
#
@@ -190,21 +192,19 @@ def main():
190192
#
191193
# Follow up the import.
192194
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()
197198
try:
198199
while not finished:
199200
if oci_cli_tools.get_lifecycle_state(display_name, compartment_id) \
200201
== 'AVAILABLE':
201202
finished = True
202203
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))
205205

206-
if system_tools.is_thread_running(importwait):
207-
importwait.stop()
206+
if system_tools.is_thread_running(import_progress):
207+
import_progress.stop()
208208
console_msg(msg='Done')
209209
return 0
210210

0 commit comments

Comments
 (0)