Skip to content

Commit

Permalink
Merge pull request #1524 from grycap/new_k8s
Browse files Browse the repository at this point in the history
New k8s
  • Loading branch information
micafer authored Feb 15, 2024
2 parents 90e8b3a + b6a7cf9 commit 4253219
Show file tree
Hide file tree
Showing 25 changed files with 506 additions and 216 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ jobs:
- name: Check code style
run: pycodestyle --max-line-length=120 --ignore=E402,W504,W605,E722 . --exclude=doc

- name: Test with nose
#run: nosetests test/unit/connectors/*.py test/unit/*.py test/functional/*.py -v --stop --with-xunit --with-coverage --cover-erase --cover-xml --cover-package=IM,contextualization
run: python -m coverage run --source=. -m unittest discover -s test/unit -p '*.py'
- name: Unit tests
run: python -m coverage run --source=. -m unittest discover -v -s test/unit -p '*.py'

- name: Generate XML coverage report
run: python -m coverage xml
Expand Down
4 changes: 2 additions & 2 deletions IM/ConfManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import time
import tempfile
import shutil
from distutils.version import LooseVersion
from packaging.version import Version

try:
from StringIO import StringIO
Expand Down Expand Up @@ -758,7 +758,7 @@ def get_vault_editor(vault_password):
"""
Get the correct VaultEditor object in different Ansible versions
"""
if LooseVersion(ansible_version) >= LooseVersion("2.4.0"):
if Version(ansible_version) >= Version("2.4.0"):
# for Ansible version 2.4.0 or higher
vault_secrets = [('default', VaultSecret(_bytes=to_bytes(vault_password)))]
return VaultEditor(VaultLib(vault_secrets))
Expand Down
6 changes: 3 additions & 3 deletions IM/ansible_utils/ansible_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import psutil
import signal
import logging
from distutils.version import LooseVersion
from packaging.version import Version
from collections import namedtuple
from ansible import errors
from ansible import __version__ as ansible_version
Expand Down Expand Up @@ -137,7 +137,7 @@ def run(self):
self._kill_childs()

def get_play_prereqs(self, options):
if LooseVersion(ansible_version) >= LooseVersion("2.4.0"):
if Version(ansible_version) >= Version("2.4.0"):
# for Ansible version 2.4.0 or higher
return self.get_play_prereqs_2_4(options)
else:
Expand Down Expand Up @@ -208,7 +208,7 @@ def version_info(ansible_version_string):
'revision': ansible_versions[2]}

def _gen_options(self):
if LooseVersion(ansible_version) >= LooseVersion("2.8.0"):
if Version(ansible_version) >= Version("2.8.0"):
from ansible.module_utils.common.collections import ImmutableDict
from ansible import context
context.CLIARGS = ImmutableDict(connection='ssh',
Expand Down
19 changes: 19 additions & 0 deletions IM/connectors/CloudConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
import yaml
import uuid
import re

from radl.radl import Feature, outport
from IM.config import Config
Expand Down Expand Up @@ -751,3 +752,21 @@ def manage_dns_entries(self, op, vm, auth_data, extra_args=None):
self.error_messages += "Error in %s DNS entries %s.\n" % (op, str(ex))
self.log_exception("Error in %s DNS entries" % op)
return False

@staticmethod
def convert_memory_unit(memory, unit="M"):
unit_dict = {'B': 1, 'K': 1000, 'Ki': 1024,
'M': 1000000, 'Mi': 1048576,
'G': 1000000000, 'Gi': 1073741824,
'T': 1000000000000, 'Ti': 1099511627776}
regex = re.compile(r'([0-9.]+)\s*([a-zA-Z]+)')
result = regex.match(str(memory)).groups()
value = float(result[0])
orig_unit = result[1]
if len(orig_unit) > 1 and orig_unit[-1] == 'B':
orig_unit = orig_unit[:-1]

converted = (value * unit_dict[orig_unit] / unit_dict[unit])
if converted - int(converted) < 0.0000000000001:
converted = int(converted)
return converted
Loading

0 comments on commit 4253219

Please sign in to comment.