-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from ARGOeu/devel
Version 0.3.0
- Loading branch information
Showing
12 changed files
with
1,301 additions
and
972 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
Summary: Script installs packages on ARGO mon boxes. | ||
Name: argo-poem-tools | ||
Version: 0.2.7 | ||
Version: 0.3.0 | ||
Release: 1%{?dist} | ||
Source0: %{name}-%{version}.tar.gz | ||
License: ASL 2.0 | ||
|
@@ -52,6 +52,8 @@ rm -rf $RPM_BUILD_ROOT | |
%attr(0755,root,root) %dir %{_localstatedir}/log/argo-poem-tools/ | ||
|
||
%changelog | ||
* Mon Jun 17 2024 Katarina Zailac <[email protected]> - 0.3.7-1%{?dist} | ||
- ARGO-4661 Make tool multi-tenant aware | ||
* Thu Apr 4 2024 Katarina Zailac <[email protected]> - 0.2.7-1%{?dist} | ||
- ARGO-4502 Generalize method for fetching distro name | ||
* Thu Aug 3 2023 Katarina Zailac <[email protected]> - 0.2.6-1%{?dist} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
[GENERAL] | ||
Host = egi.tenant.com | ||
[tenant1] | ||
Host = tenant1.example.com | ||
Token = some-token-1234 | ||
|
||
[PROFILES] | ||
MetricProfiles = TEST_PROFILE1, TEST_PROFILE2 | ||
|
||
[tenant2] | ||
Host = tenant2.example.com | ||
Token = some-token-5678 | ||
MetricProfiles = TEST_PROFILE3, TEST_PROFILE4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,59 @@ | ||
import configparser | ||
|
||
conf = '/etc/argo-poem-tools/argo-poem-tools.conf' | ||
from argo_poem_tools.exceptions import ConfigException | ||
|
||
|
||
class Config: | ||
def __init__(self): | ||
self.conf = conf | ||
def __init__(self, file="/etc/argo-poem-tools/argo-poem-tools.conf"): | ||
self.file = file | ||
self.conf = self._read() | ||
self.tenants = self._get_tenants() | ||
|
||
def read(self): | ||
def _check_file_exists(self): | ||
conf = configparser.ConfigParser() | ||
try: | ||
with open(self.file) as f: | ||
conf.read_file(f) | ||
|
||
except IOError: | ||
raise ConfigException(f"File {self.file} does not exist") | ||
|
||
def _read(self): | ||
config = configparser.ConfigParser() | ||
config.read(self.conf) | ||
config.read(self.file) | ||
return config | ||
|
||
def get_hostname(self): | ||
config = self.read() | ||
return config.get('GENERAL', 'host') | ||
def _get_tenants(self): | ||
tenants = list() | ||
for section in self.conf.sections(): | ||
if section != "GENERAL": | ||
tenants.append(section) | ||
|
||
return tenants | ||
|
||
def get_configuration(self): | ||
configuration = dict() | ||
for tenant in self.tenants: | ||
for entry in ["host", "token", "metricprofiles"]: | ||
try: | ||
if entry == "metricprofiles": | ||
profiles_string = self.conf.get(tenant, entry) | ||
value = [ | ||
p.strip() for p in profiles_string.split(',') | ||
] | ||
|
||
else: | ||
value = self.conf.get(tenant, entry) | ||
|
||
if tenant in configuration: | ||
configuration[tenant].update({entry: value}) | ||
|
||
def get_token(self): | ||
config = self.read() | ||
return config.get('GENERAL', 'token') | ||
else: | ||
configuration.update({tenant: {entry: value}}) | ||
|
||
def get_profiles(self): | ||
config = self.read() | ||
profiles_string = config.get('PROFILES', 'metricprofiles') | ||
profiles = [p.strip() for p in profiles_string.split(',')] | ||
except configparser.NoOptionError: | ||
raise ConfigException( | ||
f"Missing '{entry}' entry for tenant '{tenant}'" | ||
) | ||
|
||
return profiles | ||
return configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class MyException(Exception): | ||
def __init__(self, msg): | ||
self.msg = msg | ||
|
||
def __str__(self): | ||
return str(self.msg) | ||
|
||
|
||
class ConfigException(MyException): | ||
def __str__(self): | ||
return f"Configuration file error: {str(self.msg)}" | ||
|
||
|
||
class PackageException(MyException): | ||
pass | ||
|
||
|
||
class POEMException(MyException): | ||
def __str__(self): | ||
return f"Error fetching YUM repos: {str(self.msg)}" | ||
|
||
|
||
class MergingException(MyException): | ||
def __str__(self): | ||
return f"Error merging POEM data: {str(self.msg)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.