Example #1
0
#     inventory = cvp.get_inventory(query=filter)
#     pprint(inventory[0]['fqdn'])
#
#
# finditem('192.168.10.1')

# def ip_to_host():
#     ip_addr = raw_input('Please enter the IP address of the host: ')
#     inventory = cvp.get_inventory()
#     for key in inventory:
#         if ip_addr in key['ipAddress']:
#             print "The hostname with the IP address of %s is: " % ip_addr, key['fqdn']
#
# ip_to_host()
'''Must save funtion output (dictionary) into variable before typical .items, keys, value methods can be invoked'''
mydict = cvp.get_containers()
for item in mydict['data']:
    print item['name'], item['key']
'''adding a device to CVP and saving the state once done:'''
# add_dev = cvp.add_device_to_inventory('192.168.11.12', 'SL-DC', 'container_17_609729386866')
# time.sleep(15) #sleep between adding device, and then saving the addition:
# save_state = cvp.save_inventory()
# # print save_state

# def add_device(devip):
#     cvp.add_device_to_inventory(devip, 'SL-DC')

# configlet_name = 'VLANS'
# configlet_content = 'vlan 100\n   name DEMO\nend'
# result = client.api.add_configlet(configlet_name, configlet_content)
# pprint(result)
parser.add_argument('--suffixremove', required=True)

args = parser.parse_args()
switchuser = args.username
cvpIP = args.cvpIP
switchpass = getpass()
containertobemoved = args.containertobemoved
targetcontainer = args.targetcontainer
suffixremove = args.suffixremove

clnt = CvpClient()
clnt.connect([cvpIP], switchuser, switchpass)
clntapi = CvpApi(clnt)
app_name = ""

getContainers = clntapi.get_containers()["data"]

tree = Tree()
tree.create_node("Tenant", "Tenant")  #root

for container in getContainers:
    containername = container["name"]
    parentName = container["parentName"]
    parentId = container["parentId"]
    if containername != "Tenant":
        if tree.contains(parentName):
            if tree.contains(containername) is False:
                tree.create_node(containername,
                                 containername,
                                 parent=parentName)
        else: