Skip to content

Commit 203b0eb

Browse files
feat: ✨ add ecos _dns submodule
1 parent c0bf272 commit 203b0eb

2 files changed

Lines changed: 173 additions & 0 deletions

File tree

pyedgeconnect/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ def __init__(
13281328
self.logger.addHandler(self.console_handler)
13291329

13301330
# Imported methods
1331+
from .ecos._dns import get_appliance_dns_config, set_appliance_dns_config
13311332
from .ecos._gms import assign_orchestrator, get_orchestrator
13321333
from .ecos._interfaces import get_appliance_interfaces
13331334
from .ecos._license import is_reboot_required

pyedgeconnect/ecos/_dns.py

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# MIT License
2+
# (C) Copyright 2022 Hewlett Packard Enterprise Development LP.
3+
#
4+
# dns : DNS server and domain
5+
6+
7+
def get_appliance_dns_config(
8+
self,
9+
) -> dict:
10+
"""Get the current DNS IP address and domain names configured for
11+
your appliance
12+
13+
.. list-table::
14+
:header-rows: 1
15+
16+
* - Swagger Section
17+
- Method
18+
- Endpoint
19+
* - dns
20+
- GET
21+
- /resolver
22+
23+
:return: Returns dictionary of current appliance dns configuration\n
24+
* keyword **domain_search*** (`dict`): Domain search settings \n
25+
* keyword **<Order of search 1-6>** (`dict`): \n
26+
* keyword **self** (`int`): Order of Domain Name, which
27+
should be the same as this entry's key
28+
* keyword **domainname** (`str`): Search Domain
29+
* keyword **nameserver*** (`dict`): Name server settings \n
30+
* keyword **1** (`dict`): Primary name server\n
31+
* keyword **self** (`int`): Order of Name Server, which
32+
should be the same as this entry's key
33+
* keyword **address** (`str`): IP of DNS Server
34+
* keyword **vrf_id** (`int`): Segment ID, which default
35+
value is 0
36+
* keyword **srcinf** (`str`): Source Interface, which
37+
default value is any
38+
* keyword **2** (`dict`): Secondary name server\n
39+
* keyword **self** (`int`): Order of Name Server, which
40+
should be the same as this entry's key
41+
* keyword **address** (`str`): IP of DNS Server
42+
* keyword **vrf_id** (`int`): Segment ID, which default
43+
value is 0
44+
* keyword **srcinf** (`str`): Source Interface, which
45+
default value is any
46+
* keyword **3** (`dict`): Tertiary name server\n
47+
* keyword **self** (`int`): Order of Name Server, which
48+
should be the same as this entry's key
49+
* keyword **address** (`str`): IP of DNS Server
50+
* keyword **vrf_id** (`int`): Segment ID, which default
51+
value is 0
52+
* keyword **srcinf** (`str`): Source Interface, which
53+
default value is any
54+
:rtype: dict
55+
"""
56+
return self._get("/resolver")
57+
58+
59+
def set_appliance_dns_config(
60+
self,
61+
domain_search_settings: dict,
62+
primary_ns_address: str,
63+
primary_ns_vrf_id: int,
64+
primary_ns_source_interface: str,
65+
secondary_ns_address: str,
66+
secondary_ns_vrf_id: int,
67+
secondary_ns_source_interface: str,
68+
tertiary_ns_address: str,
69+
tertiary_ns_vrf_id: int,
70+
tertiary_ns_source_interface: str,
71+
) -> dict:
72+
"""Get the current DNS IP address and domain names configured for
73+
your appliance
74+
75+
.. list-table::
76+
:header-rows: 1
77+
78+
* - Swagger Section
79+
- Method
80+
- Endpoint
81+
* - dns
82+
- POST
83+
- /resolver
84+
85+
Example:
86+
87+
.. code-block:: python
88+
89+
domain_search_settings = {
90+
"1": {
91+
"self": 1,
92+
"domainname": "my.search.domain",
93+
},
94+
}
95+
96+
ec.set_appliance_dns_config(
97+
domain_search_settings = domain_search_settings,
98+
primary_ns_address = "192.0.2.100",
99+
primary_ns_vrf_id = 0,
100+
primary_ns_source_interface = "mgmt0",
101+
secondary_ns_address = "192.0.2.200",
102+
secondary_ns_vrf_id = 0,
103+
secondary_ns_source_interface = "",
104+
tertiary_ns_address = "",
105+
tertiary_ns_vrf_id = 0,
106+
tertiary_ns_source_interface = "",
107+
)
108+
109+
:param domain_search_settings: Domain search settings dictionary
110+
object. Up to 6 can be specified, each with a key of the
111+
order they should be applied (1-6). Example below \n
112+
* keyword **1** (`dict`): Search domain object \n
113+
* keyword **self** (`int`): Numeric ID, same as key
114+
* keyword **domainname** (`str`): Search domain,
115+
e.g. ``my.search.domain``
116+
:type domain_search_settings: dict
117+
:param primary_ns_address: Primary DNS server IP address
118+
:type primary_ns_address: str
119+
:param primary_ns_vrf_id: Segment/VRF ID to reach Primary DNS
120+
server, e.g. ``0`` for Default VRF
121+
:type primary_ns_vrf_id: int
122+
:param primary_ns_source_interface: Interface to reach Primary
123+
DNS server, e.g. ``mgmt0`` or ``lan0``
124+
:type primary_ns_source_interface: str
125+
:param secondary_ns_address: Secondary DNS server IP address
126+
:type secondary_ns_address: str
127+
:param secondary_ns_vrf_id: Segment/VRF ID to reach Secondary
128+
DNS server, e.g. ``0`` for Default VRF
129+
:type secondary_ns_vrf_id: int
130+
:param secondary_ns_source_interface: Interface to reach
131+
Secondary DNS server, e.g. ``mgmt0`` or ``lan0``
132+
:type secondary_ns_source_interface: str
133+
:param tertiary_ns_address: Tertiary DNS server IP address
134+
:type tertiary_ns_address: str
135+
:param tertiary_ns_vrf_id: Segment/VRF ID to reach Tertiary DNS
136+
server, e.g. ``0`` for Default VRF
137+
:type tertiary_ns_vrf_id: int
138+
:param tertiary_ns_source_interface: Interface to reach Tertiary
139+
DNS server, e.g. ``mgmt0`` or ``lan0``
140+
:type tertiary_ns_source_interface: str
141+
:return: Returns True/False based on successful call
142+
:rtype: bool
143+
"""
144+
data = {
145+
"domain_search": domain_search_settings,
146+
"nameserver": {
147+
"1": {
148+
"self": 1,
149+
"address": primary_ns_address,
150+
"vrf_id": primary_ns_vrf_id,
151+
"srcinf": primary_ns_source_interface,
152+
},
153+
"2": {
154+
"self": 2,
155+
"address": secondary_ns_address,
156+
"vrf_id": secondary_ns_vrf_id,
157+
"srcinf": secondary_ns_source_interface,
158+
},
159+
"3": {
160+
"self": 3,
161+
"address": tertiary_ns_address,
162+
"vrf_id": tertiary_ns_vrf_id,
163+
"srcinf": tertiary_ns_source_interface,
164+
},
165+
},
166+
}
167+
168+
return self._post(
169+
"/resolver",
170+
data=data,
171+
return_type="bool",
172+
)

0 commit comments

Comments
 (0)