Skip to content

Commit 4e11d61

Browse files
committed
updates
- consolidated all delete ingest methods to one method. - added ingest for ansible tower and CMDB
1 parent 56ab297 commit 4e11d61

1 file changed

Lines changed: 97 additions & 62 deletions

File tree

onefuse/admin.py

Lines changed: 97 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,20 +1377,6 @@ def ingest_name(self, policy_name: str, name: str,
13771377
response_json = self.request(path, template, tracking_id)
13781378
return response_json
13791379

1380-
def delete_ingested_name(self, id: str):
1381-
"""
1382-
Delete an ingested name from OneFuse - The deleted object will be
1383-
removed from the OneFuse database without deprovisioning.
1384-
1385-
Parameters
1386-
----------
1387-
id : str
1388-
ID for the Name object
1389-
"""
1390-
path = f"/customNames/{id}/ingest/"
1391-
response_json = self.deprovision_mo(path)
1392-
return response_json
1393-
13941380
def ingest_dns_reservation(self, policy_name: str, name: str,
13951381
records: list[dict],
13961382
template_properties: dict = None,
@@ -1436,20 +1422,6 @@ def ingest_dns_reservation(self, policy_name: str, name: str,
14361422
response_json = self.request(path, template, tracking_id)
14371423
return response_json
14381424

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-
14531425
def ingest_ip_address(self, policy_name: str, ip_address: str,
14541426
hostname: str, subnet: str, primary_dns: str = None,
14551427
secondary_dns: str = None, dns_suffix: str = None,
@@ -1522,20 +1494,6 @@ def ingest_ip_address(self, policy_name: str, ip_address: str,
15221494
response_json = self.request(path, template, tracking_id)
15231495
return response_json
15241496

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-
15391497
def ingest_scripting_deployment(self, policy_name: str,
15401498
provisioning_details: dict,
15411499
deprovisioning_details: dict,
@@ -1578,21 +1536,6 @@ def ingest_scripting_deployment(self, policy_name: str,
15781536
response_json = self.request(path, template, tracking_id)
15791537
return response_json
15801538

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-
15961539
def ingest_ad(self, policy_name: str, name: str, final_ou: str,
15971540
build_ou: str, state: str = "final",
15981541
security_groups: list = [], template_properties: dict = None,
@@ -1643,17 +1586,109 @@ def ingest_ad(self, policy_name: str, name: str, final_ou: str,
16431586
response_json = self.request(path, template, tracking_id)
16441587
return response_json
16451588

1646-
def delete_ingested_ad(self, id: str):
1589+
def ingest_ansible_tower(self, policy_name: str, hosts: list, limit: str,
1590+
inventory_name: str,
1591+
template_properties: dict = None,
1592+
tracking_id: str = ""):
1593+
"""
1594+
Ingest an existing Ansible Tower object to OneFuse - the policy will not
1595+
execute but an object will be added to the OneFuse database.
1596+
1597+
Parameters
1598+
----------
1599+
policy_name : str
1600+
OneFuse Ansible Tower Policy Name
1601+
hosts : list
1602+
List of Ansible Tower hosts
1603+
limit : str
1604+
Ansible Tower limit
1605+
inventory_name : str
1606+
Ansible Tower inventory name
1607+
template_properties : dict - optional
1608+
Dictionary of template properties. Ex: {'key': 'value'}
1609+
tracking_id : str - optional
1610+
OneFuse Tracking ID. If not passed, one will be returned from the
1611+
execution. Tracking IDs allow for grouping all executions for a
1612+
single object
1613+
"""
1614+
# Get Naming Policy by Name
1615+
policy_path = 'ansibleTowerPolicies'
1616+
policy_json = self.get_policy_by_name(policy_path, policy_name)
1617+
links = policy_json["_links"]
1618+
policy_url = links["self"]["href"]
1619+
workspace_url = links["workspace"]["href"]
1620+
# Ingest Ansible Tower
1621+
template = {
1622+
"policy": policy_url,
1623+
"workspace": workspace_url,
1624+
"hosts": hosts,
1625+
"limit": limit,
1626+
"inventoryName": inventory_name,
1627+
"templateProperties": template_properties
1628+
}
1629+
path = "/ansibleTowerDeployments/ingest/"
1630+
response_json = self.request(path, template, tracking_id)
1631+
return response_json
1632+
1633+
def ingest_service_now_cmdb(self, policy_name: str,
1634+
configuration_items_info: list,
1635+
execution_details: dict,
1636+
template_properties: dict = None,
1637+
tracking_id: str = ""):
16471638
"""
1648-
Delete an ingested AD object from OneFuse - The deleted object will be
1639+
Ingest an existing Service Now CMDB object to OneFuse - the policy will not
1640+
execute but an object will be added to the OneFuse database.
1641+
1642+
Parameters
1643+
----------
1644+
policy_name : str
1645+
OneFuse Service Now CMDB Policy Name
1646+
configuration_items_info : list
1647+
List representing the configuration items to ingest.
1648+
Ex: [{"ciClassName": "cmdb_ci_vmware_instance", "ciName": "ppportlapp019" }]
1649+
execution_details : dict
1650+
Dictionary of execution details.
1651+
template_properties : dict - optional
1652+
Dictionary of template properties. Ex: {'key': 'value'}
1653+
tracking_id : str - optional
1654+
OneFuse Tracking ID. If not passed, one will be returned from the
1655+
execution. Tracking IDs allow for grouping all executions for a
1656+
single object
1657+
"""
1658+
# Get Naming Policy by Name
1659+
policy_path = 'servicenowCMDBPolicies'
1660+
policy_json = self.get_policy_by_name(policy_path, policy_name)
1661+
links = policy_json["_links"]
1662+
policy_url = links["self"]["href"]
1663+
workspace_url = links["workspace"]["href"]
1664+
# Ingest Service Now CMDB
1665+
template = {
1666+
"policy": policy_url,
1667+
"workspace": workspace_url,
1668+
"configurationItemsInfo": configuration_items_info,
1669+
"executionDetails": execution_details,
1670+
"templateProperties": template_properties
1671+
}
1672+
path = "/servicenowCMDBDeployments/ingest/"
1673+
response_json = self.request(path, template, tracking_id)
1674+
return response_json
1675+
1676+
def delete_ingested_object(self, id: str, ingest_type: str):
1677+
"""
1678+
Delete an ingested object from OneFuse - The deleted object will be
16491679
removed from the OneFuse database without deprovisioning.
16501680
16511681
Parameters
16521682
----------
16531683
id : str
1654-
ID for the AD object
1655-
"""
1656-
path = f"/microsoftADComputerAccounts/{id}/ingest/"
1684+
ID for the object
1685+
ingest_type : str
1686+
Type of object to delete. Valid values: 'microsoftADComputerAccounts',
1687+
'scriptingDeployments', 'ansibleTowerDeployments', 'customNames',
1688+
'ansibleTowerPolicy', 'dnsReservations', 'ipamReservations',
1689+
'servicenowCMDBDeployments', 'servicenowConnectorDeployments'
1690+
"""
1691+
path = f"/{ingest_type}/{id}/ingest/"
16571692
response_json = self.deprovision_mo(path)
16581693
return response_json
16591694

0 commit comments

Comments
 (0)