|
| 1 | +from dataikuapi.fm.future import FMFuture |
| 2 | + |
1 | 3 | class FMVirtualNetwork(object): |
2 | | - def __init__(self, client, virtual_network_settings): |
| 4 | + def __init__(self, client, vn_data): |
3 | 5 | self.client = client |
4 | | - self.settings = virtual_network_settings |
5 | | - self.id = self.settings['id'] |
| 6 | + self.vn_data = vn_data |
| 7 | + self.id = self.vn_data['id'] |
| 8 | + |
| 9 | + def save(self): |
| 10 | + """ |
| 11 | + Update the Virtual Network. |
| 12 | + """ |
| 13 | + self.client._perform_tenant_empty("PUT", "/virtual-networks/%s" % self.id, body=self.vn_data) |
| 14 | + self.vn_data = self.client._perform_tenant_json("GET", "/virtual-networks/%s" % self.id) |
| 15 | + |
| 16 | + def delete(self): |
| 17 | + """ |
| 18 | + Delete the DSS Instance Settings Template. |
| 19 | +
|
| 20 | + :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the deletion process |
| 21 | + :rtype: :class:`~dataikuapi.fm.future.FMFuture` |
| 22 | + """ |
| 23 | + future = self.client._perform_tenant_json("DELETE", "/virtual-networks/%s" % self.id) |
| 24 | + return FMFuture.from_resp(self.client, future) |
| 25 | + |
| 26 | + def set_fleet_management(self, enable, event_server=None, deployer_management="NO_MANAGED_DEPLOYER"): |
| 27 | + """ |
| 28 | + When enabled, all instances in this virtual network know each other and can centrally manage deployer and logs centralization |
| 29 | +
|
| 30 | + :param boolean enable: Enable or not the Fleet Management |
| 31 | +
|
| 32 | + :param str event_server: Optional, Node name of the node that should act as the centralized event server for logs concentration. Audit logs of all design, deployer and automation nodes will automatically be sent there. |
| 33 | + :param str deployer_management: Optional, Accepts: |
| 34 | + - "NO_MANAGED_DEPLOYER": Do not manage the the deployer. This is the default mode. |
| 35 | + - "CENTRAL_DEPLOYER": Central deployer. Recommanded if you have more than one design node or may have more than one design node in the future. |
| 36 | + - "EACH_DESIGN_NODE": Deployer from design. Recommanded if you have a single design node and want a simpler setup. |
| 37 | + """ |
| 38 | + |
| 39 | + self.vn_data['managedNodesDirectory'] = enable |
| 40 | + self.vn_data['eventServerNodeLabel'] = event_server |
| 41 | + self.vn_data['nodesDirectoryDeployerMode'] = deployer_management |
| 42 | + self.save() |
| 43 | + |
| 44 | + def set_dns_strategy(self, assign_domain_name, aws_private_ip_zone53_id=None, aws_public_ip_zone53_id=None, azure_dns_zone_id=None): |
| 45 | + """ |
| 46 | + Set the DNS strategy for this virtual network |
| 47 | +
|
| 48 | + :param boolean assign_domain_name: If false, don't assign domain names, use ip_only |
| 49 | + :param str aws_private_ip_zone53_id: Optional, AWS Only, the ID of the AWS Route53 Zone to use for private ip |
| 50 | + :param str aws_public_ip_zone53_id: Optional, AWS Only, the ID of the AWS Route53 Zone to use for public ip |
| 51 | + :param str azure_dns_zone_id: Optional, Azure Only, the ID of the Azure DNS zone to use |
| 52 | + """ |
| 53 | + |
| 54 | + if assign_domain_name: |
| 55 | + self.vn_data['dnsStrategy'] = "VN_SPECIFIC_CLOUD_DNS_SERVICE" |
| 56 | + self.vn_data['awsRoute53PrivateIPZoneId'] = aws_private_ip_zone53_id |
| 57 | + self.vn_data['awsRoute53PublicIPZoneId'] = aws_public_ip_zone53_id |
| 58 | + self.vn_data['azureDnsZoneId'] = azure_dns_zone_id |
| 59 | + else : |
| 60 | + self.vn_data['dnsStrategy'] = "NONE" |
| 61 | + |
| 62 | + self.save() |
| 63 | + |
| 64 | + def set_https_strategy(self, https_strategy): |
| 65 | + """ |
| 66 | + Set the HTTPS strategy for this virtual network |
| 67 | +
|
| 68 | + :param object: a :class:`dataikuapi.fm.virtualnetworks.FMHTTPSStrategy` |
| 69 | + """ |
| 70 | + self.vn_data.update(https_strategy) |
| 71 | + self.save() |
| 72 | + |
| 73 | +class FMHTTPSStrategy(dict): |
| 74 | + def __init__(self, data, https_strategy, http_redirect=False): |
| 75 | + """ |
| 76 | + A class holding HTTPS Strategy for Virtual Network |
| 77 | +
|
| 78 | + Do not create this directly, use: |
| 79 | + - :meth:`dataikuapi.fm.virtualnetwork.FMHTTPSStrategy.disable` to use HTTP only |
| 80 | + - :meth:`dataikuapi.fm.virtualnetwork.FMHTTPSStrategy.self_signed` to use self-signed certificates |
| 81 | + - :meth:`dataikuapi.fm.virtualnetwork.FMHTTPSStrategy.custom_cert` to use custom certificates |
| 82 | + - :meth:`dataikuapi.fm.virtualnetwork.FMHTTPSStrategy.lets_encrypt` to use Let's Encrypt |
| 83 | + """ |
| 84 | + super(FMHTTPSStrategy, self).__init__(data) |
| 85 | + self['httpsStrategy'] = https_strategy |
| 86 | + if http_redirect: |
| 87 | + self['httpStrategy'] = "REDIRECT" |
| 88 | + else: |
| 89 | + self['httpStrategy'] = "DISABLE" |
| 90 | + |
| 91 | + @staticmethod |
| 92 | + def disable(): |
| 93 | + """ |
| 94 | + Use HTTP only |
| 95 | + """ |
| 96 | + return FMHTTPSStrategy({}, "NONE", False) |
| 97 | + |
| 98 | + @staticmethod |
| 99 | + def self_signed(http_redirect): |
| 100 | + """ |
| 101 | + Use self-signed certificates |
| 102 | +
|
| 103 | + :param bool http_redirect: If true, HTTP is redirected to HTTPS. If false, HTTP is disabled. Defaults to false |
| 104 | + """ |
| 105 | + return FMHTTPSStrategy({}, "SELF_SIGNED", http_redirect) |
| 106 | + |
| 107 | + @staticmethod |
| 108 | + def custom_cert(http_redirect): |
| 109 | + """ |
| 110 | + Use a custom certificate for each instance |
| 111 | +
|
| 112 | + :param bool http_redirect: If true, HTTP is redirected to HTTPS. If false, HTTP is disabled. Defaults to false |
| 113 | + """ |
| 114 | + return FMHTTPSStrategy({}, "CUSTOM_CERTIFICATE", http_redirect) |
| 115 | + |
| 116 | + @staticmethod |
| 117 | + def lets_encrypt(contact_mail): |
| 118 | + """ |
| 119 | + Use Let's Encrypt to generate https certificates |
| 120 | +
|
| 121 | + :param str contact_mail: The contact email provided to Let's Encrypt |
| 122 | + """ |
| 123 | + return FMHTTPSStrategy({"contactMail": contact_mail}, "LETSENCRYPT", True) |
0 commit comments