<commit_before>import sys
import requests
import base64

try:
    requests.packages.urllib3.disable_warnings()
except:
    pass

D42_USER    = 'admin'
D42_PWD     = '<PASSWORD>'
D42_URL     = 'https://192.168.3.30'


class Wipe():
    def __init__(self):
        self.headers = {
            'Authorization': 'Basic ' + base64.b64encode(D42_USER + ':' + D42_PWD),
            'Content-Type': 'application/x-www-form-urlencoded'
        }

    def delete_racks(self):
        """
        Deletes racks
        :return:
        """
        print '\n[!] Deleting racks'
        f = '/api/1.0/racks/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()
        racks = [x['rack_id'] for x in raw['racks']]

        for rack in racks:
            print '\t[-] Rack ID: %s' % rack
            f = '/api/1.0/racks/%s/' % rack
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)

    def delete_buildings(self):
        """
        Deletes buildings and rooms as well
        :return:
        """
        print '\n[!] Deleting buildings'
        f = '/api/1.0/buildings/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        buildings = [x['building_id'] for x in raw['buildings']]

        for building in buildings:
            print '\t[-] Building ID: %s' % building
            f = '/api/1.0/buildings/%s/' % building
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)

    def delete_pdus(self):
        """
        Deletes PDUs, but it does not delete PDU models
        :return:
        """
        print '\n[!] Deleting pdus'
        f = '/api/1.0/pdus/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        pdus = [x['pdu_id'] for x in raw['pdus']]

        for pdu in pdus:
            print '\t[-] PDU ID: %s' % pdu
            f = '/api/1.0/pdus/%s/' % pdu
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)


    def delete_subnets(self):
        """
        Deletes subnets and IPs as well
        :return:
        """
        print '\n[!] Deleting subnets'
        f = '/api/1.0/subnets/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        subnets = [x['subnet_id'] for x in raw['subnets']]

        for subnet in subnets:
            print '\t[-] Subnet ID: %s' % subnet
            f = '/api/1.0/subnets/%s/' % subnet
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)

    def delete_devices(self):
        """
        Deleting device one at the time. Very slow!
        :return:
        """
        print '\n[!] Deleting devices'
        f = '/api/1.0/devices/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        devices = [x['device_id'] for x in raw['Devices']]
        total = len(devices)
        i = 1
        for device in devices:
            print '\t[-] Device ID: %s [%d of %d]' % (device, i, total)
            f = '/api/1.0/devices/%s/' % device
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)
            i+=1



def main():
    w = Wipe()
    w.delete_racks()
    w.delete_buildings()
    w.delete_pdus()
    w.delete_subnets()
    w.delete_devices()



if __name__ == '__main__':
    main()
    print '\n[!] Done!'
    sys.exit()<commit_msg>Adding Options and Safety<commit_after>import sys
import requests
import base64
import argparse

try:
    requests.packages.urllib3.disable_warnings()
except:
    pass

D42_USER    = 'admin'
D42_PWD     = '<PASSWORD>'
D42_URL     = 'https://192.168.3.30'


class Wipe():
    def __init__(self):
        self.headers = {
            'Authorization': 'Basic ' + base64.b64encode(D42_USER + ':' + D42_PWD),
            'Content-Type': 'application/x-www-form-urlencoded'
        }

    def delete_racks(self):
        """
        Deletes racks
        :return:
        """
        print '\n[!] Deleting racks'
        f = '/api/1.0/racks/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()
        racks = [x['rack_id'] for x in raw['racks']]

        for rack in racks:
            print '\t[-] Rack ID: %s' % rack
            f = '/api/1.0/racks/%s/' % rack
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)

    def delete_buildings(self):
        """
        Deletes buildings and rooms as well
        :return:
        """
        print '\n[!] Deleting buildings'
        f = '/api/1.0/buildings/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        buildings = [x['building_id'] for x in raw['buildings']]

        for building in buildings:
            print '\t[-] Building ID: %s' % building
            f = '/api/1.0/buildings/%s/' % building
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)

    def delete_pdus(self):
        """
        Deletes PDUs, but it does not delete PDU models
        :return:
        """
        print '\n[!] Deleting pdus'
        f = '/api/1.0/pdus/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        pdus = [x['pdu_id'] for x in raw['pdus']]

        for pdu in pdus:
            print '\t[-] PDU ID: %s' % pdu
            f = '/api/1.0/pdus/%s/' % pdu
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)


    def delete_subnets(self):
        """
        Deletes subnets and IPs as well
        :return:
        """
        print '\n[!] Deleting subnets'
        f = '/api/1.0/subnets/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        subnets = [x['subnet_id'] for x in raw['subnets']]

        for subnet in subnets:
            print '\t[-] Subnet ID: %s' % subnet
            f = '/api/1.0/subnets/%s/' % subnet
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)

    def delete_devices(self):
        """
        Deleting device one at the time. Very slow!
        :return:
        """
        print '\n[!] Deleting devices'
        f = '/api/1.0/devices/'
        url = D42_URL+f
        response = requests.get(url,headers=self.headers, verify=False)
        raw = response.json()

        devices = [x['device_id'] for x in raw['Devices']]
        total = len(devices)
        i = 1
        for device in devices:
            print '\t[-] Device ID: %s [%d of %d]' % (device, i, total)
            f = '/api/1.0/devices/%s/' % device
            url = D42_URL + f
            r = requests.delete(url, headers=self.headers, verify=False)
            i+=1

def print_warning(section):
    print '\n'
    print '!!! WARNING !!!\n'
    print "This WILL Delete all of your %s\n" % (section)
    print '!!! WARNING !!!\n'
    response = raw_input("Please Type 'YES' to confirm deletion: ")
    if response == 'YES':
      return True
    else:
      return False

def main():
    w = Wipe()
    parser = argparse.ArgumentParser(prog="deleter")
    parser.add_argument('-r', '--racks', action="store_true", help='Delete all Racks')
    parser.add_argument('-b', '--buildings', action="store_true", help='Delete all Buildings')
    parser.add_argument('-p', '--pdus', action="store_true", help='Delete all PDUs')
    parser.add_argument('-s', '--subnets', action="store_true", help='Delete all subnets')
    parser.add_argument('-d', '--devices', action="store_true", help='Delete all Devices')
    parser.add_argument('-a', '--all', action="store_true", help='Delete EVERYTHING')
    args = parser.parse_args()
    
    if args.racks:
      if print_warning("racks"):
        print '\n Deleting Racks ...'
        w.delete_racks()
      else:
        print 'Cancelled'
        sys.exit()
    if args.buildings:
      if print_warning("buildings"):
        print '\n Deleting Buildings'
        w.delete_buildings()
      else:
        print 'Cancelled'
        sys.exit()
    if args.pdus:
      if print_warning("pdus"):
        print '\n Deleting PDUs'
        w.delete_pdus()
      else:
        print 'Cancelled'
        sys.exit()
    if args.subnets:
      if print_warning("subnets"):
        print '\n Deleting Subnets'
        w.delete_subnets()
      else:
        print 'Cancelled'
        sys.exit()
    if args.devices:
      if print_warning("EVERYTHING"):
        print '\n DELETING EVERYTHING ...'
        w.delete_racks()
        w.delete_buildings()
        w.delete_pdus()
        w.delete_subnets()
        w.delete_devices()
      else:
        print 'Cancelled'
        sys.exit() 




if __name__ == '__main__':
    main()
    print '\n[!] Done!'
    sys.exit()
{'fraction_non_alphanumeric': 0.1431950118254139, 'fraction_numerical': 0.014620511717910126, 'mean_word_length': 1.885545905707196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1613510', 'n_tokens_mistral': 3165, 'n_tokens_neox': 3041, 'n_words': 731}