Skip to content

Commit 9e8ad91

Browse files
Merge pull request #144 from guidotijskens/version0128
Version0128
2 parents 715be9e + 70354e9 commit 9e8ad91

File tree

23 files changed

+600
-218
lines changed

23 files changed

+600
-218
lines changed

MANIFEST.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ include libexec/oci-kvm-upgrade
99
include libexec/oci-kvm-config.sh
1010
include libexec/oci-kvm-network-script
1111
include tests/*.py
12+
include tests/data/*.cfg
13+
include tests/data/tests/createattachdetachattachdetachdestroy/*.cfg
14+
include tests/data/tests/test_cli_kvm/*.cfg
15+
include tests/data/tests/test_cli_network_config/*.cfg
16+
include tests/data/tests/test_cli_network_config_attach/*.cfg
17+
include tests/data/tests/test_cli_network_config_configure/*.cfg
18+
include tests/data/tests/test_exec_helpers/*.cfg
19+
include tests/data/tests/test_exec_ocid/*.cfg
20+
include tests/data/tests/test_iscsiadm/*.cfg
21+
include tests/data/tests/test_network_helpers/*.cfg
22+
include tests/data/tests/test_oci_notify/*.cfg
1223
include data/*.service
1324
include data/oci-image-cleanup.conf
1425
include data/00-oci-utils.conf
@@ -22,5 +33,7 @@ include tools/build_image/scripts/*
2233
include tools/build_image/templates/*
2334
include tools/build_image/Makefile
2435
include tools/build_image/README.md
36+
include tools/*.py
37+
include tools/execution/*
2538
include buildrpm/*.spec
2639
include man/man?/*.[158]

PKG-INFO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: oci-utils
3-
Version: 0.10.2
3+
Version: 0.12.7
44
Summary: Oracle Cloud Infrastructure utilities
55
Home-page: http://github.com/oracle/oci-utils/
66
Author: Laszlo Peter
@@ -16,7 +16,7 @@ Classifier: Intended Audience :: Information Technology
1616
Classifier: Intended Audience :: System Administrators
1717
Classifier: Natural Language :: English
1818
Classifier: Operating System :: POSIX
19-
Classifier: Programming Language :: Python :: 2.7
19+
Classifier: Programming Language :: Python :: 3.6
2020
Classifier: Topic :: System :: Installation/Setup
2121
Classifier: Topic :: System :: Systems Administration
2222
Classifier: Topic :: Utilities

buildrpm/oci-utils.spec

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: oci-utils
2-
Version: 0.12.7
3-
Release: 1%{?dist}
2+
Version: 0.12.8
3+
Release: 0%{?dist}
44
Url: http://cloud.oracle.com/iaas
55
Summary: Oracle Cloud Infrastructure utilities
66
License: UPL
@@ -18,34 +18,52 @@ BuildRequires: systemd
1818
BuildRequires: python3-devel
1919
BuildRequires: python3-setuptools
2020
Requires: python3
21-
Requires: python3-daemon
22-
Requires: python3-sdnotify
21+
#
2322
Requires: xfsprogs
2423
Requires: cloud-utils-growpart
2524
# for lsblk
2625
Requires: util-linux
2726
# for iscsiadm
2827
Requires: iscsi-initiator-utils
29-
Requires: python36-oci-sdk
3028
#
31-
%if 0%{?rhel} == 7
32-
Requires: python36-netaddr
33-
%else
29+
%if 0%{?rhel} == 9
30+
Requires: python39-oci-sdk
31+
Requires: python3-netaddr
32+
Requires: python3-daemon
33+
Requires: python3-sdnotify
34+
%endif
35+
#
36+
%if 0%{?rhel} == 8
3437
Requires: network-scripts
3538
Requires: python3-netaddr
39+
Requires: python3-daemon
40+
Requires: python3-sdnotify
3641
%endif
37-
42+
#
43+
%if 0%{?rhel} == 7
44+
Requires: python36-netaddr
45+
Requires: python36-oci-sdk
46+
Requires: python3-daemon
47+
Requires: python3-sdnotify
48+
%endif
49+
#
3850
%description
3951
A package with useful scripts for querying/validating the state of Oracle Cloud Infrastructure instances running Oracle Linux and facilitating some common configuration tasks.
4052

4153
%package kvm
4254
Summary: Utilitizes for managing virtualization in Oracle Cloud Infrastructure
4355
Group: Development/Tools
4456
Requires: %{name} = %{version}-%{release}
45-
46-
%if 0%{?rhel} >= 8
57+
#
58+
%if 0%{?rhel} == 9
59+
Requires: python3-libvirt
60+
%endif
61+
#
62+
%if 0%{?rhel} == 8
4763
Requires: python3-libvirt
48-
%else
64+
%endif
65+
#
66+
%if 0%{?rhel} == 7
4967
Requires: python36-libvirt
5068
%endif
5169

@@ -66,14 +84,25 @@ Requires: util-linux
6684
Requires: parted
6785
Requires: bind-utils
6886
Requires: qemu-img >= 15:2.12
69-
# for upload and import
87+
#
88+
%if 0%{?rhel} == 9
89+
Requires: python3
90+
Requires: python39-oci-cli
91+
Requires: python3-pyyaml
92+
%endif
93+
#
94+
%if 0%{?rhel} == 8
95+
Requires: python3
7096
Requires: python36-oci-cli
71-
%if 0%{?rhel} == 7
72-
Requires: python36-pyyaml
73-
%else
7497
Requires: python3-pyyaml
98+
%endif
99+
#
100+
%if 0%{?rhel} == 7
75101
Requires: python36
102+
Requires: python36-pyyaml
103+
Requires: python36-oci-cli
76104
%endif
105+
#
77106
%description migrate
78107
Utilities for migrating on-premise guests to Oracle Cloud Infrastructure.
79108

@@ -176,6 +205,18 @@ rm -rf %{buildroot}
176205
/opt/oci-utils/tests/__init__*
177206

178207
%changelog
208+
* Wed Mar 30 2022 Guido Tijskens <guido.tijskens@oracle.com> -- 0.12.7-3
209+
- spec file fixed for ol9 builds of oci-kvm and oci-migrate
210+
- tests for instance distribution and version
211+
212+
* Wed Mar 09 2022 Guido Tijskens <guido.tijskens@oracle.com> -- 0.12.7-2
213+
- LINUX-11994 oci-utils for OL9
214+
- adjust oci-kvm guest test
215+
- show-all option for oci-iscsi-config
216+
- LINUX-12111 oci-public-ip (oci-utils) does not show the reason why no public ip's are returned.
217+
- LINUX-12119 oci-public-ip does not have the correct ordering in "primary on top"
218+
- update oci-kvm
219+
179220
* Wed Feb 16 2022 Guido Tijskens <guido.tijskens@oracle.com> -- 0.12.7-1
180221
- LINUX-12109 Local iSCSI info not available" after running oci-iscsi-config sync
181222
- LINUX-12114 oci-utils help info contains ref to python main module iso the command

lib/oci_utils/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# at http://oss.oracle.com/licenses/upl.
66

77
import logging
8+
import re
89
import os
910
import os.path
1011

@@ -136,6 +137,46 @@ def find_exec_in_path(exec_name):
136137
return result
137138

138139

140+
def is_root_user():
141+
"""
142+
Verify if operator has root privileges.
143+
144+
Returns
145+
-------
146+
bool: True if root, False otherwise.
147+
"""
148+
if os.geteuid() != 0:
149+
return False
150+
return True
151+
152+
153+
def get_os_release_data():
154+
"""
155+
Collect information on the linux operating system and release.
156+
Currently is only able to handle linux type os.
157+
158+
Returns
159+
-------
160+
ostype: str
161+
The os type
162+
major_release: str
163+
the major release
164+
dict: Dictionary containing the os and version data on success,
165+
None otherwise.
166+
"""
167+
osdata = '/etc/os-release'
168+
try:
169+
with open(osdata, 'r') as f:
170+
osreleasedata = [line.strip() for line in f.read().splitlines() if '=' in line]
171+
osdict = dict([re.sub(r'"', '', kv).split('=') for kv in osreleasedata])
172+
except Exception as e:
173+
return None, None, None
174+
os_type = osdict['ID']
175+
major_release = re.split('\\.', osdict['VERSION_ID'])[0]
176+
177+
return os_type, major_release, osdict
178+
179+
139180
def _set_proxy():
140181
"""
141182
Set the proxy for OCI metadata service access.

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,51 @@ def qemu_img_version():
221221
return 0
222222

223223

224+
def get_os_release_data():
225+
"""
226+
Collect information on the linux operating system and release.
227+
Currently is only able to handle linux type os.
228+
229+
Returns
230+
-------
231+
ostype: str
232+
The os type
233+
major_release: str
234+
the major release
235+
dict: Dictionary containing the os and version data on success,
236+
None otherwise.
237+
"""
238+
osdata = '/etc/os-release'
239+
try:
240+
with open(osdata, 'r') as f:
241+
osreleasedata = [line.strip() for line in f.read().splitlines() if '=' in line]
242+
osdict = dict([re.sub(r'"', '', kv).split('=') for kv in osreleasedata])
243+
except Exception as e:
244+
return None, None, None
245+
os_type = osdict['ID']
246+
major_release = re.split('\\.', osdict['VERSION_ID'])[0]
247+
248+
return os_type, major_release, osdict
249+
250+
251+
def verify_support():
252+
"""
253+
Verify if the instance os and release are supported to run this code.
254+
255+
Returns
256+
-------
257+
bool: True on success, False otherwise.
258+
"""
259+
ostype, majorrelease, _ = get_os_release_data()
260+
if ostype not in ['ol', 'redhat', 'centos']:
261+
_logger.info('OS type %s is not supported.', ostype)
262+
return False
263+
if majorrelease not in ['7', '8']:
264+
_logger.info('OS %s %s is not supported', ostype, majorrelease)
265+
return False
266+
return True
267+
268+
224269
def main():
225270
"""
226271
Main
@@ -249,6 +294,10 @@ def main():
249294
else:
250295
exit_with_msg(' *** ERROR *** This program needs to be run with root privileges.')
251296
#
297+
# Verify if instance is supported to run this code.
298+
if not verify_support():
299+
sys.exit(1)
300+
#
252301
# Verbose mode is False by default
253302
migrate_data.verbose_flag = args.verbose_flag
254303
_logger.debug('Verbose level set to %s', migrate_data.verbose_flag)

lib/oci_utils/impl/oci-growfs-main.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import termios
1717
import tty
1818

19-
from oci_utils import find_exec_in_path
19+
from oci_utils import is_root_user, find_exec_in_path
2020
from oci_utils.lsblk import lsblk_partition_data
2121

2222
lc_all = 'en_US.UTF8'
@@ -140,45 +140,6 @@ def _read_yn(prompt, yn=True, waitenter=False, suppose_yes=False, suppose_no=Fal
140140
return bool(yn.upper() == 'Y')
141141

142142

143-
def is_root_user():
144-
"""
145-
Verify if operator has root privileges.
146-
147-
Returns
148-
-------
149-
bool: True if root, False otherwise.
150-
"""
151-
if os.geteuid() != 0:
152-
_logger.error("This program needs to be run with root privileges.")
153-
return False
154-
return True
155-
156-
157-
# def find_exec_in_path(exec_name):
158-
# """
159-
# Find an executable in the path.
160-
#
161-
# Parameters
162-
# ----------
163-
# exec_name: str
164-
# The name of the executable.
165-
#
166-
# Returns
167-
# -------
168-
# str: the full path of the executable.
169-
# """
170-
# path = os.getenv('PATH').split(':')
171-
# result = None
172-
# for rootdir in path:
173-
# for root, folder, files in os.walk(rootdir):
174-
# if exec_name in files:
175-
# result = os.path.join(root, exec_name)
176-
# break
177-
# if result:
178-
# break
179-
# return result
180-
181-
182143
def partition_growfs_X(partition_data, dry_run=True):
183144
"""
184145
Expand a partition.
@@ -698,6 +659,7 @@ def main():
698659
#
699660
# root privileges are required.
700661
if not is_root_user():
662+
_logger.error('This program needs to be run with root privileges')
701663
sys.exit(1)
702664
#
703665
# the command line.

0 commit comments

Comments
 (0)