Skip to content

Commit 3ea7e81

Browse files
author
Thibaud Baas
committed
FM: FMInstanceCreator
1 parent bd41121 commit 3ea7e81

2 files changed

Lines changed: 107 additions & 2 deletions

File tree

dataikuapi/fm/instances.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,104 @@
11
from enum import Enum
22
from .future import FMFuture
33

4+
class FMInstanceCreator(object):
5+
def __init__(self, client, label, instance_settings_template_id, virtual_network_id, image_id):
6+
"""
7+
Helper to create a DSS Instance
8+
9+
:param str instance_settings_template: The instance settings template id this instance should be based on
10+
:param str virtual_network: The virtual network where the instance should be spawned
11+
:param str label: The label of the instance
12+
:param str image_id: The ID of the DSS runtime image (ex: dss-9.0.3-default)
13+
"""
14+
self.client = client
15+
self.data = {}
16+
self.data["label"] = label
17+
self.data["instanceSettingsTemplateId"] = instance_settings_template_id
18+
self.data["virtualNetworkId"] = virtual_network_id
19+
self.data["imageId"] = image_id
20+
21+
# Set the default value for dssNodeType
22+
self.data["dssNodeType"] = "design"
23+
24+
def create(self):
25+
"""
26+
Create the DSS instance
27+
28+
:return: Instance
29+
:rtype: :class:`dataikuapi.fm.instances.FMInstance`
30+
"""
31+
instance = self.client._perform_tenant_json("POST", "/instances", body=self.data)
32+
return FMInstance(self.client, instance)
33+
34+
def set_dss_node_type(self, dss_node_type):
35+
"""
36+
Set the DSS Node type of the instance to create
37+
38+
:param str dss_node_type: Optional , the type of the dss node to create. Supports "design", "automation ordeployer". Defaults to "design"
39+
"""
40+
if dss_node_type not in ["design", "automation", "deployer"]:
41+
raise ValueError("Only \"design\", \"automation\" or \"deployer\" dss_node_type are supported")
42+
self.data["dssNodeType"] = dss_node_type
43+
44+
def set_cloud_instance_type(self, cloud_instance_type):
45+
"""
46+
Set the machine type for the DSS Instance
47+
"""
48+
self.data["cloudInstanceType"] = cloud_instance_type
49+
50+
def set_data_volume_options(self, data_volume_type=None, data_volume_size=None, data_volume_size_max=None, data_volume_IOPS=None, data_volume_encryption=None, data_volume_encryption_key=None):
51+
"""
52+
Set the options of the data volume to use with the DSS Instance
53+
54+
:param str data_volume_type: Optional, Data volume type
55+
:param int data_volume_size: Optional, Data volume initial size
56+
:param int data_volume_size_max: Optional, Data volume maximum size
57+
:param int data_volume_IOPS: Optional, Data volume IOPS
58+
:param object data_volume_encryption: Optional, a :class:`dataikuapi.fm.instances.FMInstanceEncryptionMode` setting the encryption mode of the data volume
59+
:param str data_volume_encryption_key: Optional, the encryption key to use when data_volume_encryption_key is FMInstanceEncryptionMode.CUSTOM
60+
"""
61+
if type(data_volume_encryption) is not FMInstanceEncryptionMode:
62+
raise TypeError("data_volume encryption needs to be of type FMInstanceEncryptionMode")
63+
64+
self.data["dataVolumeType"] = data_volume_type
65+
self.data["dataVolumeSizeGB"] = data_volume_size
66+
self.data["dataVolumeSizeMaxGB"] = data_volume_size_max
67+
self.data["dataVolumeIOPS"] = data_volume_IOPS
68+
self.data["dataVolumeEncryption"] = data_volume_encryption.value
69+
self.data["dataVolumeEncryptionKey"] = data_volume_encryption_key
70+
71+
def set_aws_root_volume_options(self, aws_root_volume_size=None, aws_root_volume_type=None, aws_root_volume_IOPS=None):
72+
"""
73+
AWS Only: Set the options of the root volume of the DSS Instance
74+
75+
:param int aws_root_volume_size: Optional, the root volume size
76+
:param str aws_root_volume_type: Optional, the root volume type
77+
:param int aws_root_volume_IOPS: Optional, the root volume IOPS
78+
"""
79+
if self.client.cloud != "AWS":
80+
raise BaseException("set_aws_root_volume_options is only usable on AWS tenants")
81+
self.data["awsRootVolumeSizeGB"] = aws_root_volume_size
82+
self.data["awsRootVolumeType"] = aws_root_volume_type
83+
self.data["awsRootVolumeIOPS"] = aws_root_volume_IOPS
84+
85+
def set_cloud_tags(self, cloud_tags):
86+
"""
87+
Set the tags to be applied to the cloud resources created for this DSS instance
88+
89+
:param dict cloud_tags: a key value dictionary of tags to be applied on the cloud resources
90+
"""
91+
self.data["cloudTags"] = cloud_tags
92+
93+
def set_fm_tags(self, fm_tags):
94+
"""
95+
A list of tags to add on the DSS Instance in Fleet Manager
96+
97+
:param list fm_tags: Optional, list of tags to be applied on the instance in the Fleet Manager
98+
"""
99+
self.data["fmTags"] = fm_tags
100+
101+
4102
class FMInstance(object):
5103
"""
6104
A handle to interact with a DSS instance.

dataikuapi/fmclient.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from requests import Session
33
from requests import exceptions
44
from requests.auth import HTTPBasicAuth
5-
65
import os.path as osp
6+
7+
from enum import Enum
78
from .utils import DataikuException
89

910
from .fm.tenant import FMCloudCredentials
@@ -14,17 +15,23 @@
1415
class FMClient(object):
1516
"""Entry point for the FM API client"""
1617

17-
def __init__(self, host, api_key_id, api_key_secret, tenant_id="main", extra_headers=None):
18+
def __init__(self, host, api_key_id, api_key_secret, cloud, tenant_id="main", extra_headers=None):
1819
"""
1920
Instantiate a new FM API client on the given host with the given API key.
2021
2122
API keys can be managed in FM on the project page or in the global settings.
2223
2324
The API key will define which operations are allowed for the client.
25+
26+
:param str host: Full url of the FM
27+
2428
"""
2529
self.api_key_id = api_key_id
2630
self.api_key_secret = api_key_secret
2731
self.host = host
32+
if cloud not in ["AWS", "Azure"]:
33+
raise ValueError("cloud should be either \"AWS\" or \"Azure\"")
34+
self.cloud = cloud
2835
self.__tenant_id = tenant_id
2936
self._session = Session()
3037

0 commit comments

Comments
 (0)