-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anja Strunk <[email protected]>
- Loading branch information
1 parent
89893c3
commit 328727a
Showing
9 changed files
with
52 additions
and
34 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[flake8] | ||
ignore = E501 | ||
ignore = E501, W503 |
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
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
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 |
---|---|---|
|
@@ -3,37 +3,33 @@ | |
(c) Anja Strunk <[email protected]>, 2/2024 | ||
SPDX-License-Identifier: EPL-2.0 | ||
""" | ||
import json | ||
import os | ||
import uuid | ||
from datetime import datetime | ||
|
||
from hashlib import sha256 | ||
from typing import List | ||
|
||
import requests | ||
from jinja2 import Environment, FileSystemLoader, select_autoescape | ||
from linkml_runtime.utils import yamlutils | ||
from openstack.connection import Connection | ||
from requests.exceptions import HTTPError | ||
|
||
from generator.common import const | ||
from generator.common.config import Config | ||
from generator.common.gx_schema import DataAccountExport, TermsAndConditions, VirtualMachineServiceOffering | ||
from generator.discovery.openstack.server_flavor_discovery import \ | ||
ServerFlavorDiscovery | ||
from generator.common.gx_schema import ( | ||
DataAccountExport, | ||
TermsAndConditions, | ||
VirtualMachineServiceOffering, | ||
) | ||
from generator.discovery.openstack.server_flavor_discovery import ServerFlavorDiscovery | ||
from generator.discovery.openstack.vm_images_discovery import VmImageDiscovery | ||
|
||
|
||
|
||
class OsCloud: | ||
"""Abstraction for openStack cloud with all its services.""" | ||
|
||
def __init__(self, conn: Connection, config: Config) -> None: | ||
# import copy | ||
self.conn = conn | ||
# self.regions = list(conn.identity.regions()) | ||
self.config = config | ||
|
||
@property | ||
def discover(self) -> VirtualMachineServiceOffering: | ||
""" | ||
Discover all attributes of OS Cloud. | ||
|
@@ -48,33 +44,58 @@ def discover(self) -> VirtualMachineServiceOffering: | |
# Create Virtual Service Offering object | ||
data_export_account = DataAccountExport( | ||
requestType=self.config.get_value( | ||
[const.CONFIG_IAAS, const.CONFIG_IAAS_DATA_EXPORT, const.CONFIG_IAAS_DATA_EXPORT_REQ_TYPE]), | ||
[ | ||
const.CONFIG_IAAS, | ||
const.CONFIG_IAAS_DATA_EXPORT, | ||
const.CONFIG_IAAS_DATA_EXPORT_REQ_TYPE, | ||
] | ||
), | ||
accessType=self.config.get_value( | ||
[const.CONFIG_IAAS, const.CONFIG_IAAS_DATA_EXPORT, const.CONFIG_IAAS_DATA_EXPORT_ACCESS_TYPE]), | ||
[ | ||
const.CONFIG_IAAS, | ||
const.CONFIG_IAAS_DATA_EXPORT, | ||
const.CONFIG_IAAS_DATA_EXPORT_ACCESS_TYPE, | ||
] | ||
), | ||
formatType=self.config.get_value( | ||
[const.CONFIG_IAAS, const.CONFIG_IAAS_DATA_EXPORT, const.CONFIG_IAAS_DATA_EXPORT_FORMAT_TYPE]) | ||
[ | ||
const.CONFIG_IAAS, | ||
const.CONFIG_IAAS_DATA_EXPORT, | ||
const.CONFIG_IAAS_DATA_EXPORT_FORMAT_TYPE, | ||
] | ||
), | ||
) | ||
terms_and_conditions = [] | ||
for url in self.config.get_value([const.CONFIG_IAAS, const.CONFIG_IAAS_T_AND_C]): | ||
serivce_tac = [] | ||
for url in self.config.get_value( | ||
[const.CONFIG_IAAS, const.CONFIG_IAAS_T_AND_C] | ||
): | ||
httpResponse = requests.get(url) | ||
if httpResponse.status_code == 200: | ||
content = httpResponse.text | ||
terms_and_conditions.append(TermsAndConditions(url=url, hash=sha256(content.encode("utf-8")).hexdigest())) | ||
serivce_tac.append( | ||
TermsAndConditions( | ||
url=url, hash=sha256(content.encode("utf-8")).hexdigest() | ||
) | ||
) | ||
else: | ||
raise HTTPError( | ||
"Cloud not retrieve terms and conditions from '" + url + "'. HTTP Status code: " + str( | ||
httpResponse.status_code)) | ||
"Cloud not retrieve terms and conditions from '" | ||
+ url + "'. HTTP Status code: " + str(httpResponse.status_code) | ||
) | ||
|
||
if len(terms_and_conditions) == 0: | ||
if len(serivce_tac) == 0: | ||
raise ValueError( | ||
"Service offerings terms and conditions MUST not be empty. Please check config.yaml. " | ||
+ "There MUST be at least on entry in " + const.CONFIG_IAAS + "." + const.CONFIG_IAAS_T_AND_C) | ||
"Service offerings terms and conditions MUST not be empty. Please check config.yaml. There MUST be at least on entry in " | ||
+ const.CONFIG_IAAS + "." + const.CONFIG_IAAS_T_AND_C | ||
) | ||
|
||
return VirtualMachineServiceOffering( | ||
providedBy=self.config.get_value([const.CONFIG_CSP, const.CONFIG_DID]), | ||
dataAccountExport=data_export_account, | ||
servicePolicy=self.config.get_value([const.CONFIG_IAAS, const.CONFIG_IAAS_SERVICE_POLICY]), | ||
serviceOfferingTermsAndConditions=terms_and_conditions, | ||
servicePolicy=self.config.get_value( | ||
[const.CONFIG_IAAS, const.CONFIG_IAAS_SERVICE_POLICY] | ||
), | ||
serviceOfferingTermsAndConditions=serivce_tac, | ||
codeArtifact=images, | ||
instantiationReq=flavors | ||
instantiationReq=flavors, | ||
) |
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
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