Skip to content

Commit 3da4edd

Browse files
author
Thibaud Baas
committed
fm: Virtual network management
1 parent e4e00b5 commit 3da4edd

2 files changed

Lines changed: 169 additions & 5 deletions

File tree

dataikuapi/fm/virtualnetworks.py

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,123 @@
1+
from dataikuapi.fm.future import FMFuture
2+
13
class FMVirtualNetwork(object):
2-
def __init__(self, client, virtual_network_settings):
4+
def __init__(self, client, vn_data):
35
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)

dataikuapi/fmclient.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,54 @@ def get_virtual_network(self, virtual_network_id):
7575
:return: requested virtual network
7676
:rtype: :class:`dataikuapi.fm.virtualnetworks.FMVirtualNetwork`
7777
"""
78-
template = self._perform_tenant_json("GET", "/virtual-networks/%s" % virtual_network_id)
79-
return FMVirtualNetwork(self, template)
78+
vn = self._perform_tenant_json("GET", "/virtual-networks/%s" % virtual_network_id)
79+
return FMVirtualNetwork(self, vn)
80+
81+
def create_virtual_network(self,
82+
label,
83+
awsVpcId=None,
84+
awsSubnetId=None,
85+
awsAutoCreateSecurityGroups=False,
86+
awsSecurityGroups=None,
87+
azureVnId=None,
88+
azureSubnetId=None,
89+
azureAutoUpdateSecurityGroups=None,
90+
internetAccessMode = "YES"):
91+
"""
92+
Create a Virtual Network
93+
94+
:param str label: The label of the Virtual Network
95+
96+
:param str awsVpcId: AWS Only, ID of the VPC to use
97+
:param str awsSubnetId: AWS Only, ID of the subnet to use
98+
:param boolean awsAutoCreateSecurityGroups: Optional, AWS Only, If false, do not create security groups automatically. Defaults to false
99+
:param list awsSecurityGroups: Optional, AWS Only, A list of up to 5 security group ids to assign to the instances created in this virtual network. Ignored if awsAutoCreateSecurityGroups is true
100+
101+
:param str azureVnId: Azure Only, ID of the Azure Virtual Network to use
102+
:param str azureSubnetId: Azure Only, ID of the subnet to use
103+
:param boolean azureAutoUpdateSecurityGroups: Azure Only, Auto update the subnet security group
104+
105+
:param str internetAccessMode: Optional, The internet access mode of the instances created in this virtual network. Accepts "YES", "NO", "EGRESS_ONLY". Defaults to "YES"
106+
107+
:return: requested instance settings template
108+
:rtype: :class:`dataikuapi.fm.instancesettingstemplates.FMInstanceSettingsTemplate`
109+
"""
110+
111+
data = {
112+
"label": label,
113+
"awsVpcId": awsVpcId,
114+
"awsSubnetId": awsSubnetId,
115+
"awsAutoCreateSecurityGroups": awsAutoCreateSecurityGroups,
116+
"awsSecurityGroups": awsSecurityGroups,
117+
"azureVnId": azureVnId,
118+
"azureSubnetId": azureSubnetId,
119+
"azureAutoUpdateSecurityGroups": azureAutoUpdateSecurityGroups,
120+
"internetAccessMode": internetAccessMode,
121+
"mode": "EXISTING_MONOTENANT"
122+
}
123+
124+
vn = self._perform_tenant_json("POST", "/virtual-networks", body=data)
125+
return FMVirtualNetwork(self, vn)
80126

81127

82128
########################################################

0 commit comments

Comments
 (0)