|
1 | 1 | from enum import Enum |
2 | 2 | from .future import FMFuture |
3 | 3 |
|
| 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 | + |
4 | 102 | class FMInstance(object): |
5 | 103 | """ |
6 | 104 | A handle to interact with a DSS instance. |
|
0 commit comments