Skip to content

Commit 423bfb1

Browse files
committed
DNS, IPAM, Scripting Ingest
Added support for DNS, IPAM and Scripting Ingest Also updated each ingest call to allow for pass of template_properties
1 parent fa7edca commit 423bfb1

1 file changed

Lines changed: 207 additions & 3 deletions

File tree

onefuse/admin.py

Lines changed: 207 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,8 @@ def get_onefuse_instance_id(self):
13401340
return None
13411341

13421342
def ingest_name(self, policy_name: str, name: str,
1343-
dns_suffix: str = "", tracking_id: str = ""):
1343+
dns_suffix: str = "", template_properties: dict = None,
1344+
tracking_id: str = ""):
13441345
"""
13451346
Ingest an existing name to OneFuse - the policy will not execute but
13461347
an object will be added to the OneFuse database.
@@ -1369,7 +1370,8 @@ def ingest_name(self, policy_name: str, name: str,
13691370
"policy": policy_url,
13701371
"workspace": workspace_url,
13711372
"name": name,
1372-
"dnsSuffix": dns_suffix
1373+
"dnsSuffix": dns_suffix,
1374+
"templateProperties": template_properties
13731375
}
13741376
path = "/customNames/ingest/"
13751377
response_json = self.request(path, template, tracking_id)
@@ -1388,7 +1390,209 @@ def delete_ingested_name(self, id: str):
13881390
path = f"/customNames/{id}/ingest/"
13891391
response_json = self.deprovision_mo(path)
13901392
return response_json
1391-
1393+
1394+
def ingest_dns_reservation(self, policy_name: str, name: str,
1395+
records: list[dict],
1396+
template_properties: dict = None,
1397+
tracking_id: str = ""):
1398+
"""
1399+
Ingest an existing DNS Reservation to OneFuse - the policy will not
1400+
execute but an object will be added to the OneFuse database.
1401+
1402+
Parameters
1403+
----------
1404+
policy_name : str
1405+
OneFuse DNS Policy Name
1406+
name : str
1407+
Name for the Name object, typically a hostname
1408+
records : list(dict
1409+
List of records to be included in DNS reservation.
1410+
Ex: [{"type": "a", "value": "10.1.0.60", "name": "test.example.com"}]
1411+
Valid types: a, ptr, host (infoblox only)
1412+
tracking_id : str - optional
1413+
OneFuse Tracking ID. If not passed, one will be returned from the
1414+
execution. Tracking IDs allow for grouping all executions for a
1415+
single object
1416+
"""
1417+
# Get Naming Policy by Name
1418+
policy_path = 'dnsPolicies'
1419+
policy_json = self.get_policy_by_name(policy_path, policy_name)
1420+
links = policy_json["_links"]
1421+
policy_url = links["self"]["href"]
1422+
workspace_url = links["workspace"]["href"]
1423+
# Validate records
1424+
for record in records:
1425+
if record["type"] not in ["a", "ptr", "host"]:
1426+
raise ValueError(f"Invalid DNS record type: {record['type']}")
1427+
# Ingest DNS Reservation
1428+
template = {
1429+
"policy": policy_url,
1430+
"workspace": workspace_url,
1431+
"name": name,
1432+
"records": records,
1433+
"templateProperties": template_properties
1434+
}
1435+
path = "/dnsReservations/ingest/"
1436+
response_json = self.request(path, template, tracking_id)
1437+
return response_json
1438+
1439+
def delete_ingested_dns_reservation(self, id: str):
1440+
"""
1441+
Delete an ingested DNS Reservation from OneFuse - The deleted object
1442+
will be removed from the OneFuse database without deprovisioning.
1443+
1444+
Parameters
1445+
----------
1446+
id : str
1447+
ID for the Name object
1448+
"""
1449+
path = f"/dnsReservations/{id}/ingest/"
1450+
response_json = self.deprovision_mo(path)
1451+
return response_json
1452+
1453+
def ingest_ip_address(self, policy_name: str, ip_address: str,
1454+
hostname: str, subnet: str, primary_dns: str = None,
1455+
secondary_dns: str = None, dns_suffix: str = None,
1456+
dns_search_suffixes: str = None, gateway: str = None,
1457+
netmask: str = None, network: str = None,
1458+
template_properties: dict = None,
1459+
nic_label: str = None, tracking_id: str = ""):
1460+
"""
1461+
Ingest an existing IP Address to OneFuse - the policy will not
1462+
execute but an object will be added to the OneFuse database.
1463+
1464+
Parameters
1465+
----------
1466+
policy_name : str
1467+
OneFuse IPAM Policy Name
1468+
ip_address : str
1469+
IP Address for the IP Address object. Ex: '10.1.0.25
1470+
hostname : str
1471+
Hostname for the IP Address object. Ex. 'myhost.example.com'
1472+
subnet : str
1473+
Value for the Subnet in CIDR notation. Ex: '10.1.0.0/24'
1474+
primary_dns : str
1475+
Optional Primary DNS for the IP Address object. Ex: '10.0.0.10
1476+
secondary_dns : str
1477+
Optional Secondary DNS for the IP Address object. Ex: '10.0.0.10
1478+
dns_suffix : str
1479+
Optional Value for the DNS Suffix. Ex: 'example.com'
1480+
dns_search_suffixes : str
1481+
Optional Value for the DNS Search Suffixes. Comma separated.
1482+
Ex: 'example.com,example2.com'
1483+
gateway : str
1484+
Optional Value for the Gateway. Ex: '10.1.0.1'
1485+
netmask : str
1486+
Optional Value for the Netmask. Ex: '255.255.255.0'
1487+
network : str
1488+
Optional Value for the Network. Ex: 'NameOfPortGroupInVcenter'
1489+
nic_label : str
1490+
Optional - Value for the NIC Label. Ex: 'eth0'
1491+
template_properties : dict
1492+
Optional - Dictionary of template properties. Ex: {'key': 'value'}
1493+
tracking_id : str - optional
1494+
OneFuse Tracking ID. If not passed, one will be returned from the
1495+
execution. Tracking IDs allow for grouping all executions for a
1496+
single object
1497+
"""
1498+
# Get Naming Policy by Name
1499+
policy_path = 'ipamPolicies'
1500+
policy_json = self.get_policy_by_name(policy_path, policy_name)
1501+
links = policy_json["_links"]
1502+
policy_url = links["self"]["href"]
1503+
workspace_url = links["workspace"]["href"]
1504+
# Ingest IP Address
1505+
template = {
1506+
"policy": policy_url,
1507+
"workspace": workspace_url,
1508+
"ipAddress": ip_address,
1509+
"hostname": hostname,
1510+
"primaryDns": primary_dns,
1511+
"secondaryDns": secondary_dns,
1512+
"dnsSuffix": dns_suffix,
1513+
"dnsSearchSuffixes": dns_search_suffixes,
1514+
"nicLabel": nic_label,
1515+
"gateway": gateway,
1516+
"netmask": netmask,
1517+
"network": network,
1518+
"subnet": subnet,
1519+
"templateProperties": template_properties
1520+
}
1521+
path = "/ipamReservations/ingest/"
1522+
response_json = self.request(path, template, tracking_id)
1523+
return response_json
1524+
1525+
def delete_ingested_ip_address(self, id: str):
1526+
"""
1527+
Delete an ingested IP Address from OneFuse - The deleted object will be
1528+
removed from the OneFuse database without deprovisioning.
1529+
1530+
Parameters
1531+
----------
1532+
id : str
1533+
ID for the IP Address object
1534+
"""
1535+
path = f"/ipamReservations/{id}/ingest/"
1536+
response_json = self.deprovision_mo(path)
1537+
return response_json
1538+
1539+
def ingest_scripting_deployment(self, policy_name: str,
1540+
provisioning_details: dict,
1541+
deprovisioning_details: dict,
1542+
template_properties: dict = None,
1543+
tracking_id: str = ""):
1544+
"""
1545+
Ingest an existing Scripting Deployment to OneFuse - the policy will not
1546+
execute but an object will be added to the OneFuse database.
1547+
1548+
Parameters
1549+
----------
1550+
policy_name : str
1551+
OneFuse Scripting Policy Name
1552+
provisioning_details : dict
1553+
Scripting provisioning details.
1554+
Ex. {"status": "successful", "output": []}
1555+
deprovisioning_details : dict
1556+
Scripting deprovisioning details
1557+
template_properties : dict
1558+
tracking_id : str - optional
1559+
OneFuse Tracking ID. If not passed, one will be returned from the
1560+
execution. Tracking IDs allow for grouping all executions for a
1561+
single object
1562+
"""
1563+
# Get Naming Policy by Name
1564+
policy_path = 'scriptingPolicies'
1565+
policy_json = self.get_policy_by_name(policy_path, policy_name)
1566+
links = policy_json["_links"]
1567+
policy_url = links["self"]["href"]
1568+
workspace_url = links["workspace"]["href"]
1569+
# Ingest Scripting Deployment
1570+
template = {
1571+
"policy": policy_url,
1572+
"workspace": workspace_url,
1573+
"provisioning_details": provisioning_details,
1574+
"deprovisioning_details": deprovisioning_details,
1575+
"templateProperties": template_properties
1576+
}
1577+
path = "/scriptingDeployments/ingest/"
1578+
response_json = self.request(path, template, tracking_id)
1579+
return response_json
1580+
1581+
def delete_ingested_scripting_deployment(self, id: str):
1582+
"""
1583+
Delete an ingested Scripting Deployment from OneFuse - The deleted
1584+
object will be removed from the OneFuse database without
1585+
deprovisioning.
1586+
1587+
Parameters
1588+
----------
1589+
id : str
1590+
ID for the Scripting Deployment object
1591+
"""
1592+
path = f"/scriptingDeployments/{id}/ingest/"
1593+
response_json = self.deprovision_mo(path)
1594+
return response_json
1595+
13921596

13931597
if __name__ == '__main__':
13941598
username = sys.argv[1] # 'OneFuse Username'

0 commit comments

Comments
 (0)