Skip to content
Snippets Groups Projects
Commit a473c31a authored by Juraj Paluba's avatar Juraj Paluba
Browse files

update base cloud client class and rename subdirectory

parent 7b42770f
No related branches found
No related tags found
No related merge requests found
from kypo.commons.cloud_client_base import KypoCloudClientBase
from kypo.commons.topology_instance import TopologyInstance
from kypo.commons.transformation_configuration import TransformationConfiguration
from kypo.commons.exceptions import KypoException, StackException, StackCreationFailed,\
from kypo.cloud_commons.cloud_client_base import KypoCloudClientBase
from kypo.cloud_commons.topology_instance import TopologyInstance
from kypo.cloud_commons.transformation_configuration import TransformationConfiguration
from kypo.cloud_commons.exceptions import KypoException, StackException, StackCreationFailed,\
InvalidTopologyDefinition
from kypo.cloud_commons.topology_elements import MAN, SecurityGroups, Link, NodeToNodeLinkPair
from kypo.cloud_commons.exceptions import KypoException, StackException, StackCreationFailed,\
InvalidTopologyDefinition
from kypo.commons.topology_elements import MAN, SecurityGroups, Link, NodeToNodeLinkPair
......@@ -2,63 +2,161 @@ from abc import ABC, abstractmethod
from typing import List
from kypo.topology_definition.models import TopologyDefinition
from kypo.commons.cloud_client_elements import Image, QuotaSet, HardwareUsage, Limits
from kypo.cloud_commons.cloud_client_elements import Image, QuotaSet, HardwareUsage, Limits
class KypoCloudClientBase(ABC):
"""
Base class for KYPO cloud clients.
"""
@abstractmethod
def create_terraform_template(self, topology_definition: TopologyDefinition, *args, **kwargs)\
-> str:
"""
Create terraform template that will be deployed.
:param topology_definition: TopologyDefinition instance used to create template
:keyword key_pair_name_ssh: The name of SSH key pair in the cloud
:keyword key_pair_name_cert: The name of certificate key pair in the cloud
:keyword resource_prefix: The prefix of all resources
:return: Terraform template as a string
:raise KypoException: Network validation error
:raise InvalidTopologyDefinition: Template rendering error
"""
pass
@abstractmethod
def list_images(self) -> List[Image]:
"""
List all available images on the cloud project.
:return: List of Image objects.
"""
pass
@abstractmethod
def get_image(self, image_id: int) -> Image:
"""
Get Image object based on its ID.
:param image_id: The ID of image on the cloud
:return: Image object
"""
pass
@abstractmethod
def resume_node(self, resource_id: int):
def resume_node(self, node_id: int) -> None:
"""
Resume node.
:param node_id: The ID of the node
:return: None
:raise KypoException: Node not found
"""
pass
@abstractmethod
def start_node(self, resource_id: int):
def start_node(self, node_id: int) -> None:
"""
Start node.
:param node_id: The ID of the node
:return: None
:raise KypoException: Node not found
"""
pass
@abstractmethod
def reboot_node(self, resource_id: int):
def reboot_node(self, node_id: int) -> None:
"""
Reboot node.
:param node_id: The ID of the node
:return: None
:raise KypoException: Node not found
"""
pass
@abstractmethod
def get_console_url(self, resource_id: str, console_type: str) -> str:
def get_console_url(self, node_id: str, console_type: str) -> str:
"""
Get console for given node.
:param node_id: The ID of the node
:param console_type: Type can be novnc, xvpvnc, spice-html5, rdp-html5, serial and webmks
:return: Console url
:raise KypoException: Node not found
"""
pass
@abstractmethod
def create_keypair(self, name: str, public_key: str = None, key_type: str = 'ssh'):
def create_keypair(self, name: str, public_key: str = None, key_type: str = 'ssh') -> None:
"""
Create key pair in cloud.
:param name: Name of the key pair
:param public_key: SSH public key or certificate, it None new is created
:param key_type: Accepted vales are 'ssh' and 'x509'. Is used as suffix to 'name' parameter
:return: None
:raise KypoException: Creation failure
"""
pass
@abstractmethod
def get_keypair(self, name: str):
"""
Get KeyPair instance from cloud.
:param name: The name of key pair
:return: KeyPair instance
:raise KypoException: Key pair does not exist
"""
pass
@abstractmethod
def delete_keypair(self, name: str):
def delete_keypair(self, name: str) -> None:
"""
Delete key pair.
:param name: The name of key pair
:return: None
:raise KypoException: Key pair does not exist
"""
pass
@abstractmethod
def get_quota_set(self) -> QuotaSet:
"""
Get quota set of cloud project.
:return: QuotaSet object
"""
pass
@abstractmethod
def get_project_name(self) -> str:
"""
Get project name from application credentials.
:return: The name of the cloud project
"""
pass
@abstractmethod
def get_hardware_usage(self, topology_instance) -> HardwareUsage:
"""
Get hardware usage of a single sandbox.
:param topology_instance: Topology instance from which the sandbox is created
:return: HardwareUsage object
"""
pass
@abstractmethod
def get_project_limits(self) -> Limits:
"""
Get resources limits of cloud project.
:return: Limits object
"""
pass
from typing import Union, Dict, List
from kypo.cloud_commons.exceptions import KypoException
class Image:
......@@ -94,8 +95,8 @@ class Quota:
def check_limit(self, requested: int, resource_name: str):
required = self.in_use + requested
if required > self.limit:
raise Exception(f'Cloud limits will be exceeded (required: {required},'
f' maximum: {self.limit} [{resource_name}]).') # TODO: use custom exception
raise KypoException(f'Cloud limits will be exceeded (required: {required},'
f' maximum: {self.limit} [{resource_name}]).')
class QuotaSet:
......
......@@ -6,10 +6,10 @@ from kypo.topology_definition.models \
import TopologyDefinition, NetworkMappingList, RouterList, RouterMappingList, \
Group, Network, Host, Router
from kypo.commons.transformation_configuration \
from kypo.cloud_commons.transformation_configuration \
import TransformationConfiguration
from kypo.commons.exceptions import KypoException
from kypo.commons.topology_elements \
from kypo.cloud_commons.exceptions import KypoException
from kypo.cloud_commons.topology_elements \
import MAN, Node, Link, NodeToNodeLinkPair, SecurityGroups
MAN_NAME = 'man' # Management Node
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment