-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHCP_Creation.py
51 lines (34 loc) · 1.24 KB
/
DHCP_Creation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Taging import attach_tag
def create_dhcp(client,dhcp_name,domain_name):
# Check whether DHCP is created of not
DhcpOptionsId = find_dhcp(client,dhcp_name)
if DhcpOptionsId is None:
response = client.create_dhcp_options(
DhcpConfigurations=[
{
'Key': 'domain-name-servers',
'Values': [
'AmazonProvidedDNS'
],
},
{
'Key': 'domain-name',
'Values': [
domain_name
],
},
],
)
DhcpOptionsId = response['DhcpOptions']['DhcpOptionsId']
attach_tag(client,DhcpOptionsId,dhcp_name)
print('DHCP is created with ID: ', dhcp_id)
return DhcpOptionsId
else:
return DhcpOptionsId
def find_dhcp(client,dhcp_name):
filters = [{'Name': 'tag:Name', 'Values': [dhcp_name] }]
response = client.describe_dhcp_options(Filters=filters)
if len(response['DhcpOptions']) > 0:
return response['DhcpOptions'][0]['DhcpOptionsId']
else:
return None