def delete_platform(self, platform_name): """Delete platform :param platform_name: Name of platform to delete :return: bool True if successful otherwise raise DeleteException """ try: platform_id = self.get_platforms(name=platform_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('platform: {}'.format(platform_name)) from None return self.netbox_con.delete('/dcim/platforms/', platform_id)
def delete_interface_template(self, interface_template_name): """Delete interface template :param interface_template_name: Name of interface template to delete :return: bool True if successful otherwise raise DeleteException """ try: interface_template_id = self.get_interface_templates(name=interface_template_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('interface-template: {}'.format(interface_template_name)) from None return self.netbox_con.delete('/dcim/interface-templates/', interface_template_id)
def delete_device_role(self, device_role): """Delete device by device role :param device_role: name of the role :return: bool True if successful otherwise raise DeleteException """ try: device_role_id = self.get_device_roles(name=device_role)[0]['id'] except IndexError: raise exceptions.NotFoundException('device-role: {}'.format(device_role)) from None return self.netbox_con.delete('/dcim/device-roles/', device_role_id)
def delete_manufacturer(self, manufacturer_name): """Delete manufacturer :param manufacturer_name: Name of manufacturer to delete :return: bool True if successful otherwise raise DeleteException """ try: manufacturer_id = self.get_manufacturers(name=manufacturer_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('manufacturer: {}'.format(manufacturer_name)) from None return self.netbox_con.delete('/dcim/manufacturers/', manufacturer_id)
def delete_vrf(self, vrf_name): """Delete vrf :param vrf_name: Name of vrf to delete :return: bool True if successful otherwise raise DeleteException """ try: vrf_id = self.get_vrfs(name=vrf_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('vrf: {}'.format(vrf_name)) from None return self.netbox_con.delete('/ipam/vrfs/', vrf_id)
def delete_role(self, role_name): """Delete prefix/vlan role :param role_name: prefix/vlan role to delete :return: bool True if successful otherwise raise DeleteException """ try: role_id = self.get_roles(name=role_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('prefix/vlan role: {}'.format(role_name)) from None return self.netbox_con.delete('/ipam/role/', role_id)
def delete_rack_group(self, name): """Delete rack group :param name: Name of the rack group to delete :return: bool True if successful otherwise raise DeleteException """ try: rack_group_id = self.get_rack_groups(name=name)[0]['id'] except IndexError: raise exceptions.NotFoundException('rack-group: {}'.format(name)) from None return self.netbox_con.delete('/dcim/rack-groups/', rack_group_id)
def delete_provider(self, provider_name): """Delete circuit provider :param provider_name: circuit provider to delete :return: bool True if successful otherwise delete exception """ try: circuits_provider_id = self.get_providers(name=provider_name)[0]['id'] except IndexError: raise exceptions.NotFoundException({"detail": "circuit provider: {}".format(provider_name)}) from None return self.netbox_con.delete('/circuits/providers/', circuits_provider_id)
def delete_vlan_group(self, name): """Delete VLAN group :param name: name of the vlan-group to delete :return: bool True if successful otherwise raise DeleteException """ try: vgrp_id = self.get_vlan_groups(name=name)[0]['id'] except IndexError: raise exceptions.NotFoundException('vlan: {}'.format(name)) from None return self.netbox_con.delete('/ipam/vlan-groups/', vgrp_id)
def delete_ip_address(self, ip_address): """Delete IP address :param ip_address: IP address to delete :return: bool True if successful otherwise raise DeleteException """ try: ip_id = self.get_ip_addresses(address=ip_address)[0]['id'] except IndexError: raise exceptions.NotFoundException('ip: {}'.format(ip_address)) from None return self.netbox_con.delete('/ipam/ip-addresses/', ip_id)
def delete_vlan(self, vid): """Delete VLAN based on VLAN ID :param vid: vlan id to delete :return: bool True if successful otherwise raise DeleteException """ try: vid_id = self.get_vlans(vid=vid)[0]['id'] except IndexError: raise exceptions.NotFoundException('vlan: {}'.format(vid)) from None return self.netbox_con.delete('/ipam/vlans/', vid_id)
def delete_device(self, device_name): """Delete device by device name :param device_name: Device to delete :return: bool True if successful otherwise raise DeleteException """ try: device_id = self.get_devices(name=device_name)[0]['id'] except IndexError: raise exceptions.NotFoundException({"detail": "device: {}".format(device_name)}) from None return self.netbox_con.delete('/dcim/devices/', device_id)
def delete_rack(self, rack_name): """Delete rack :param rack_name: Name of the rack to delete :return: bool True if successful otherwise raise DeleteException """ try: rack_id = self.get_racks(name=rack_name)[0]['id'] except IndexError: raise exceptions.NotFoundException({"detail": "rack: {}".format(rack_name)}) from None return self.netbox_con.delete('/dcim/racks/', rack_id)
def delete_tag(self, name): """Delete tag :param name: Name of the tag to delete :return: bool True if succesful otherwase delete exception """ try: tag_id = self.get_tags(name=name)[0]['id'] except IndexError: raise exceptions.NotFoundException('tag: {}'.format(name)) from None return self.netbox_con.delete('/extras/tags/', tag_id)
def get_devices_per_rack(self, rack_name, **kwargs): """Get devices which belongs to the given rack :param rack_name: Name of the rack :return: list of devices otherwise an empty list """ try: rack_id = self.get_racks(name=rack_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('rack: {}'.format(rack_name)) from None return self.netbox_con.get('/dcim/devices', rack_id=rack_id, **kwargs)
def delete_type(self, type_name): """Delete circuit type :param type_name: circuit type to delete :return: bool True if succesful otherwase delete exception """ try: circuits_type_id = self.get_types(name=type_name)[0]['id'] except IndexError: raise exceptions.NotFoundException({"detail": "circuit type: {}".format(type_name)}) from None return self.netbox_con.delete('/circuits/circuit-types/', circuits_type_id)
def delete_device_type(self, model_name): """Delete device type :param model_name: Name of the model :return: bool True if successful otherwise raise DeleteException """ try: device_type_id = self.get_device_types(model=model_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('device-type: {}'.format(model_name)) from None return self.netbox_con.delete('/dcim/device-types/', device_type_id)
def delete_ip_prefix(self, **kwargs): """Delete IP prefix :param kwargs: Delete prefix based on filter values :return: bool True if successful otherwise raise DeleteException """ try: ip_prefix_id = self.get_ip_prefixes(**kwargs)[0]['id'] except IndexError: raise exceptions.NotFoundException('ip-prefix') from None return self.netbox_con.delete('/ipam/prefixes/', ip_prefix_id)
def delete_region(self, region_name): """Delete region :param region_name: Region to delete :return: bool True if succesful otherwase delete exception """ try: region_id = self.get_regions(name=region_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('region: {}'.format(region_name)) from None return self.netbox_con.delete('/dcim/regions/', region_id)
def delete_rir(self, rir_name): """Delete rir :param rir_name: rir name to delete :return: bool True if successful otherwise raise DeleteException """ try: rir_id = self.get_rirs(name=rir_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('rir: {}'.format(rir_name)) from None return self.netbox_con.delete('/ipam/rirs/', rir_id)
def delete_site(self, site_name): """Delete site :param site_name: Site to delete :return: bool True if succesful otherwase delete exception """ try: site_id = self.get_sites(name=site_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('site: {}'.format(site_name)) from None return self.netbox_con.delete('/dcim/sites/', site_id)
def delete_config_context(self, name): """Delete config-context :param name: Name of the config-context to delete :return: bool True if succesful otherwase delete exception """ try: config_context_id = self.get_config_contexts(name=name)[0]['id'] except IndexError: raise exceptions.NotFoundException('config-context: {}'.format(name)) from None return self.netbox_con.delete('/extras/config-contexts/', config_context_id)
def delete_cluster(self, name): """Delete a cluster :param name: name of the cluster to delete :return: bool True if succesful otherwase delete exception """ try: cluster_id = self.get_cluster(name=name)[0]['id'] except IndexError: raise exceptions.NotFoundException( 'cluster {}'.format(name)) from None return self.netbox_con.delete('/virtualization/clusters/', cluster_id)
def update_ip(self, ip_address, **kwargs): """Update ip address :param ip_address: ip address with prefix. Format: 1.1.1.1/32 :param kwargs: requests body dict :return: bool True if successful otherwise raise UpdateException """ try: ip_id = self.get_ip_addresses(q=ip_address)[0]['id'] except IndexError: raise exceptions.NotFoundException('ip: {}'.format(ip_address)) from None return self.netbox_con.patch('/ipam/ip-addresses/', ip_id, **kwargs)
def patch(self, params, key, **kwargs): body_data = {key: value for (key, value) in kwargs.items()} resp_ok, resp_status, resp_data = self.__request('PATCH', params=params, key=key, body=body_data) if resp_ok and resp_status == 200: return resp_data if resp_status == 404: raise exceptions.NotFoundException("object not found with id {}".format(key), from_con=True) raise exceptions.UpdateException(resp_data)
def update_vlan_group(self, name, **kwargs): """Update vlan-group :param name: name of the vlan-group :param kwargs: arguments :return: bool True if successful otherwise raise UpdateException """ try: vgrp_ip = self.get_vlan_groups(name=name)[0]['id'] except IndexError: raise exceptions.NotFoundException('name: {}'.format(name)) from None return self.netbox_con.patch('/ipam/vlan-groups/', vgrp_ip, **kwargs)
def update_vlan(self, vlan_name, **kwargs): """Update vlan :param vlan_name: Name of the vlan :param kwargs: requests body dict :return: bool True if successful otherwise raise UpdateException """ try: vlan_id = self.get_vlans(name=vlan_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('vlan: {}'.format(vlan_name)) from None return self.netbox_con.patch('/ipam/vlans/', vlan_id, **kwargs)
def update_role(self, role_name, **kwargs): """Update prefix role :param role_name: Name of the prefix/vlan role :param kwargs: requests body dict :return: bool True if successful otherwise raise UpdateException """ try: prefix_role_id = self.get_roles(name=role_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('prefix/vlan role: {}'.format(role_name)) from None return self.netbox_con.patch('/ipam/roles/', prefix_role_id, **kwargs)
def update_rir(self, rir_name, **kwargs): """Update rir :param rir_name: Name of the rir :param kwargs: requests body dict :return: bool True if successful otherwise raise UpdateException """ try: rir_id = self.get_rirs(name=rir_name)[0]['id'] except IndexError: raise exceptions.NotFoundException('rir: {}'.format(rir_name)) from None return self.netbox_con.patch('/ipam/rirs/', rir_id, **kwargs)
def update_aggregate(self, prefix, **kwargs): """Update aggregate :param prefix: Prefix of the aggregate :param kwargs: requests body dict :return: bool True if successful otherwise raise UpdateException """ try: aggregate_id = self.get_aggregates(prefix=prefix)[0]['id'] except IndexError: raise exceptions.NotFoundException('aggregate: {}'.format(prefix)) from None return self.netbox_con.patch('/ipam/aggregates/', aggregate_id, **kwargs)