Skip to content

Commit

Permalink
Reformat files
Browse files Browse the repository at this point in the history
Signed-off-by: Anja Strunk <[email protected]>
  • Loading branch information
anjastrunk committed May 30, 2024
1 parent 89893c3 commit 328727a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[flake8]
ignore = E501
ignore = E501, W503
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ devops/plugins/
node_modules
.gx-credentials/
*.tar.gz
htmlcov
# Make sure credentials not push to the repo
os_secret
k8s_secret
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,3 @@ version(s), and exceptions or additional permissions here}."
look for such a notice.

You may add additional accurate notices of copyright ownership.

2 changes: 1 addition & 1 deletion generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def openstack(cloud, timeout, config):
os_cloud = OsCloud(conn, Config(config_dict))

# run discovery
creds = os_cloud.discover()
creds = os_cloud.discover

props = json_ld.get_json_ld_context()
props["@graph"] = creds
Expand Down
3 changes: 1 addition & 2 deletions generator/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def __init__(self, config):
def get_value(self, keys: List[str]):
try:
return _get_value(self.config, keys)
except KeyError as ke:
except KeyError:
raise KeyError("Config file missing following keys: " + str(keys))


def get_copyright_owner(self, software: str) -> List[str]:
return self.get_value([const.CONFIG_SOFTWARE, software, const.CONFIG_COPYRIGHT])

Expand Down
73 changes: 47 additions & 26 deletions generator/discovery/openstack/openstack_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
)
1 change: 0 additions & 1 deletion generator/discovery/openstack/server_flavor_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from generator.common.gx_schema import (Disk, DiskType, Frequency, Hypervisor,
HypervisorType, Memory, MemorySize)
from generator.common.gx_schema import ServerFlavor as GX_Flavor
from generator.common.json_ld import JsonLdObject
from generator.vendor.flavor_names import Flavorname, parser_v3

# map SCS hypervisor names to corresponding GX type and config key
Expand Down
1 change: 0 additions & 1 deletion generator/discovery/openstack/vm_images_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
VMDiskType)
from generator.common.gx_schema import VMImage as GX_Image
from generator.common.gx_schema import WatchDogActions
from generator.common.json_ld import JsonLdObject

VALID_UNTIL_LOOKUP = {
"none": Validity1.none.text,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_openstack_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setUp(self):
conn=MockConnection(images=[OS_IMAGE_1], flavors=[OS_FLAVOR_1]), config=get_config())

def test_discovery(self):
claim = self.discovery.discover()
claim = self.discovery.discover
pass


Expand Down

0 comments on commit 328727a

Please sign in to comment.