@@ -473,7 +473,7 @@ def export_pluggable_module(self, module_name: str, save_path: str,
473473 os .remove (file_path )
474474 else :
475475 raise OneFuseError (f'Zip file already exists for module_name: '
476- f'{ module_name } in save_path: { save_path } ' )
476+ f'{ module_name } in save_path: { save_path } ' )
477477 with open (file_path , 'wb' ) as fd :
478478 for chunk in response .iter_content (chunk_size = 128 ):
479479 fd .write (chunk )
@@ -1339,6 +1339,359 @@ def get_onefuse_instance_id(self):
13391339 f'1.4' )
13401340 return None
13411341
1342+ def ingest_name (self , policy_name : str , name : str ,
1343+ dns_suffix : str = "" , template_properties : dict = None ,
1344+ tracking_id : str = "" ):
1345+ """
1346+ Ingest an existing name to OneFuse - the policy will not execute but
1347+ an object will be added to the OneFuse database.
1348+
1349+ Parameters
1350+ ----------
1351+ policy_name : str
1352+ OneFuse Custom Naming Policy Name
1353+ name : str
1354+ Name for the Name object, typically a hostname
1355+ dns_suffix : str
1356+ Value for the DNS Suffix. Ex: 'example.com'
1357+ tracking_id : str - optional
1358+ OneFuse Tracking ID. If not passed, one will be returned from the
1359+ execution. Tracking IDs allow for grouping all executions for a
1360+ single object
1361+ """
1362+ # Get Naming Policy by Name
1363+ policy_path = 'namingPolicies'
1364+ policy_json = self .get_policy_by_name (policy_path , policy_name )
1365+ links = policy_json ["_links" ]
1366+ policy_url = links ["self" ]["href" ]
1367+ workspace_url = links ["workspace" ]["href" ]
1368+ # Ingest Name
1369+ template = {
1370+ "policy" : policy_url ,
1371+ "workspace" : workspace_url ,
1372+ "name" : name ,
1373+ "dnsSuffix" : dns_suffix ,
1374+ "templateProperties" : template_properties
1375+ }
1376+ path = "/customNames/ingest/"
1377+ response_json = self .request (path , template , tracking_id )
1378+ return response_json
1379+
1380+ def ingest_dns_reservation (self , policy_name : str , name : str ,
1381+ records : list [dict ],
1382+ template_properties : dict = None ,
1383+ tracking_id : str = "" ):
1384+ """
1385+ Ingest an existing DNS Reservation to OneFuse - the policy will not
1386+ execute but an object will be added to the OneFuse database.
1387+
1388+ Parameters
1389+ ----------
1390+ policy_name : str
1391+ OneFuse DNS Policy Name
1392+ name : str
1393+ Name for the Name object, typically a hostname
1394+ records : list(dict
1395+ List of records to be included in DNS reservation.
1396+ Ex: [{"type": "a", "value": "10.1.0.60", "name": "test.example.com"}]
1397+ Valid types: a, ptr, host (infoblox only)
1398+ tracking_id : str - optional
1399+ OneFuse Tracking ID. If not passed, one will be returned from the
1400+ execution. Tracking IDs allow for grouping all executions for a
1401+ single object
1402+ """
1403+ # Get Naming Policy by Name
1404+ policy_path = 'dnsPolicies'
1405+ policy_json = self .get_policy_by_name (policy_path , policy_name )
1406+ links = policy_json ["_links" ]
1407+ policy_url = links ["self" ]["href" ]
1408+ workspace_url = links ["workspace" ]["href" ]
1409+ # Validate records
1410+ for record in records :
1411+ if record ["type" ] not in ["a" , "ptr" , "host" ]:
1412+ raise ValueError (f"Invalid DNS record type: { record ['type' ]} " )
1413+ # Ingest DNS Reservation
1414+ template = {
1415+ "policy" : policy_url ,
1416+ "workspace" : workspace_url ,
1417+ "name" : name ,
1418+ "records" : records ,
1419+ "templateProperties" : template_properties
1420+ }
1421+ path = "/dnsReservations/ingest/"
1422+ response_json = self .request (path , template , tracking_id )
1423+ return response_json
1424+
1425+ def ingest_ip_address (self , policy_name : str , ip_address : str ,
1426+ hostname : str , subnet : str , primary_dns : str = None ,
1427+ secondary_dns : str = None , dns_suffix : str = None ,
1428+ dns_search_suffixes : str = None , gateway : str = None ,
1429+ netmask : str = None , network : str = None ,
1430+ template_properties : dict = None ,
1431+ nic_label : str = None , tracking_id : str = "" ):
1432+ """
1433+ Ingest an existing IP Address to OneFuse - the policy will not
1434+ execute but an object will be added to the OneFuse database.
1435+
1436+ Parameters
1437+ ----------
1438+ policy_name : str
1439+ OneFuse IPAM Policy Name
1440+ ip_address : str
1441+ IP Address for the IP Address object. Ex: '10.1.0.25
1442+ hostname : str
1443+ Hostname for the IP Address object. Ex. 'myhost.example.com'
1444+ subnet : str
1445+ Value for the Subnet in CIDR notation. Ex: '10.1.0.0/24'
1446+ primary_dns : str
1447+ Optional Primary DNS for the IP Address object. Ex: '10.0.0.10
1448+ secondary_dns : str
1449+ Optional Secondary DNS for the IP Address object. Ex: '10.0.0.10
1450+ dns_suffix : str
1451+ Optional Value for the DNS Suffix. Ex: 'example.com'
1452+ dns_search_suffixes : str
1453+ Optional Value for the DNS Search Suffixes. Comma separated.
1454+ Ex: 'example.com,example2.com'
1455+ gateway : str
1456+ Optional Value for the Gateway. Ex: '10.1.0.1'
1457+ netmask : str
1458+ Optional Value for the Netmask. Ex: '255.255.255.0'
1459+ network : str
1460+ Optional Value for the Network. Ex: 'NameOfPortGroupInVcenter'
1461+ nic_label : str
1462+ Optional - Value for the NIC Label. Ex: 'eth0'
1463+ template_properties : dict
1464+ Optional - Dictionary of template properties. Ex: {'key': 'value'}
1465+ tracking_id : str - optional
1466+ OneFuse Tracking ID. If not passed, one will be returned from the
1467+ execution. Tracking IDs allow for grouping all executions for a
1468+ single object
1469+ """
1470+ # Get Naming Policy by Name
1471+ policy_path = 'ipamPolicies'
1472+ policy_json = self .get_policy_by_name (policy_path , policy_name )
1473+ links = policy_json ["_links" ]
1474+ policy_url = links ["self" ]["href" ]
1475+ workspace_url = links ["workspace" ]["href" ]
1476+ # Ingest IP Address
1477+ template = {
1478+ "policy" : policy_url ,
1479+ "workspace" : workspace_url ,
1480+ "ipAddress" : ip_address ,
1481+ "hostname" : hostname ,
1482+ "primaryDns" : primary_dns ,
1483+ "secondaryDns" : secondary_dns ,
1484+ "dnsSuffix" : dns_suffix ,
1485+ "dnsSearchSuffixes" : dns_search_suffixes ,
1486+ "nicLabel" : nic_label ,
1487+ "gateway" : gateway ,
1488+ "netmask" : netmask ,
1489+ "network" : network ,
1490+ "subnet" : subnet ,
1491+ "templateProperties" : template_properties
1492+ }
1493+ path = "/ipamReservations/ingest/"
1494+ response_json = self .request (path , template , tracking_id )
1495+ return response_json
1496+
1497+ def ingest_scripting_deployment (self , policy_name : str ,
1498+ provisioning_details : dict ,
1499+ deprovisioning_details : dict ,
1500+ template_properties : dict = None ,
1501+ tracking_id : str = "" ):
1502+ """
1503+ Ingest an existing Scripting Deployment to OneFuse - the policy will not
1504+ execute but an object will be added to the OneFuse database.
1505+
1506+ Parameters
1507+ ----------
1508+ policy_name : str
1509+ OneFuse Scripting Policy Name
1510+ provisioning_details : dict
1511+ Scripting provisioning details.
1512+ Ex. {"status": "successful", "output": []}
1513+ deprovisioning_details : dict
1514+ Scripting deprovisioning details
1515+ template_properties : dict
1516+ tracking_id : str - optional
1517+ OneFuse Tracking ID. If not passed, one will be returned from the
1518+ execution. Tracking IDs allow for grouping all executions for a
1519+ single object
1520+ """
1521+ # Get Naming Policy by Name
1522+ policy_path = 'scriptingPolicies'
1523+ policy_json = self .get_policy_by_name (policy_path , policy_name )
1524+ links = policy_json ["_links" ]
1525+ policy_url = links ["self" ]["href" ]
1526+ workspace_url = links ["workspace" ]["href" ]
1527+ # Ingest Scripting Deployment
1528+ template = {
1529+ "policy" : policy_url ,
1530+ "workspace" : workspace_url ,
1531+ "provisioning_details" : provisioning_details ,
1532+ "deprovisioning_details" : deprovisioning_details ,
1533+ "templateProperties" : template_properties
1534+ }
1535+ path = "/scriptingDeployments/ingest/"
1536+ response_json = self .request (path , template , tracking_id )
1537+ return response_json
1538+
1539+ def ingest_ad (self , policy_name : str , name : str , final_ou : str ,
1540+ build_ou : str , state : str = "final" ,
1541+ security_groups : list = [], template_properties : dict = None ,
1542+ tracking_id : str = "" ):
1543+ """
1544+ Ingest an existing AD object to OneFuse - the policy will not execute
1545+ but an object will be added to the OneFuse database.
1546+
1547+ Parameters
1548+ ----------
1549+ policy_name : str
1550+ OneFuse AD Policy Name
1551+ name : str
1552+ AD Name
1553+ final_ou : str
1554+ AD Final OU
1555+ build_ou : str
1556+ AD Build OU
1557+ state : str - optional
1558+ AD State. Default is 'final'
1559+ security_groups : list - optional
1560+ List of security groups to add to the AD.
1561+ template_properties : dict - optional
1562+ Dictionary of template properties. Ex: {'key': 'value'}
1563+ tracking_id : str - optional
1564+ OneFuse Tracking ID. If not passed, one will be returned from the
1565+ execution. Tracking IDs allow for grouping all executions for a
1566+ single object
1567+ """
1568+ # Get Naming Policy by Name
1569+ policy_path = 'microsoftADPolicies'
1570+ policy_json = self .get_policy_by_name (policy_path , policy_name )
1571+ links = policy_json ["_links" ]
1572+ policy_url = links ["self" ]["href" ]
1573+ workspace_url = links ["workspace" ]["href" ]
1574+ # Ingest AD
1575+ template = {
1576+ "policy" : policy_url ,
1577+ "workspace" : workspace_url ,
1578+ "name" : name ,
1579+ "finalOu" : final_ou ,
1580+ "buildOu" : build_ou ,
1581+ "state" : state ,
1582+ "securityGroups" : security_groups ,
1583+ "templateProperties" : template_properties
1584+ }
1585+ path = "/microsoftADComputerAccounts/ingest/"
1586+ response_json = self .request (path , template , tracking_id )
1587+ return response_json
1588+
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 = "" ):
1638+ """
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
1679+ removed from the OneFuse database without deprovisioning.
1680+
1681+ Parameters
1682+ ----------
1683+ id : str
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/"
1692+ response_json = self .deprovision_mo (path )
1693+ return response_json
1694+
13421695
13431696if __name__ == '__main__' :
13441697 username = sys .argv [1 ] # 'OneFuse Username'
0 commit comments