def main():
    fqdn = '192.168.167.101'  #change to your cluster
    username = '******'
    password = '******'

    #httplib.HTTPConnection.debuglevel = 1
    logging.basicConfig()
    logging.getLogger().setLevel(logging.CRITICAL)
    logging.captureWarnings(True)

    #connect, secure=False allows us to bypass the CA validation
    api = isilon.API(fqdn, username, password, secure=False)

    # not necessary as it will connect automatically on auth failure
    # but this avoids the initial attempt failure
    print("Connecting")
    api.session.connect()

    #Check for old bad snaps and delete
    print("Checking for older snaps")
    if api.platform.snapshot('testsnap'):
        print("We found an existing testsnap, let's delete that...")
        api.platform.snapshot_delete('testsnap')

    #This shows how we can pass params directly to the API though specifically not called
    #out as a param for the snapshot_create function.
    print("create a snapshot on %s, to expire in 60 seconds" % testfolder)
    api.platform.snapshot_create("testsnap",
                                 testfolder,
                                 expires=int(time.time() + 60))

    print("confirm test snapshot was created details:")
    print(api.platform.snapshot('testsnap'))

    print("Modify the snapshot expire time and rename to testsnap2")
    api.platform.snapshot_modify('testsnap',
                                 name='testsnap2',
                                 expires=int(time.time() + 120))

    print("Rename back testsnap")
    api.platform.snapshot_modify('testsnap2', name='testsnap')

    #debug last API call:
    api.session.debug_last()

    #list all snaps
    print('\nListing of All Snaps:')
    for snap in api.platform.snapshot(limit=2):
        print("Name: %s, Path: %s, Created: %s" %
              (snap['name'], snap['path'], time.ctime(snap['created'])))

    #cleanup our testnsap
    api.platform.snapshot_delete('testsnap')

    print("list all quotas")
    for q in api.platform.quota():
        pcnt_used = 100 * q['usage']['logical'] / q['thresholds']['hard']
        print("Path %s  Persona: %s   Percent Used: %s" %
              (q['path'], q['persona'], pcnt_used))
 def test_snap_change(self):
     #expire test snaps 60 seconds into the future
     expires = int(time.time()) + 600
     api = isilon.API(fqdn,user,password,secure=False)
     api.platform.snapshot_create(testsnap,"/ifs/data",expires=expires)
     self.assertGreater(len(api.platform.snapshot(testsnap)),0)
     self.assertGreater(len(api.platform.snapshot()),0)
     api.platform.snapshot_modify(testsnap,expires=expires+1)
     self.assertEqual(api.platform.snapshot(testsnap)[0]['expires'], expires+1)
     api.platform.snapshot_delete(testsnap)
Exemple #3
0
def main():
    parser = argparse.ArgumentParser(description='list api docs')
    parser.add_argument('-url',
                        dest='url',
                        default='',
                        help='filter only paths with this string in it')
    parser.add_argument('-method', dest='method', default='get', help='method')
    parser.add_argument('-v',
                        action='store_true',
                        dest='verbose',
                        default=False,
                        help='verbose')

    args = parser.parse_args()

    api = isilon.API("192.168.167.101", "root", "a", secure=False)
    pp = pprint.PrettyPrinter(indent=4)

    data = api.session.api_call("GET", "/platform/1/?describe&list&all")

    all_keys = {}

    for dir in data['directory']:

        if not args.url or args.url == dir:

            data1 = api.session.api_call("GET",
                                         "/platform" + dir + "?describe&json")

            # print(data1)

            if not data1 is None:
                for k in data1:
                    all_keys[k] = True

            all_args = dir + '  Props: '

            #cloud api's don't have docs yeti
            if (not data1 is None):
                for key in data1:
                    if args.method.upper() in key.upper(
                    ) and 'properties' in data1[key]:
                        print(key)
                        if args.verbose:
                            pp.pprint(data1[key])

                        for prop in data1[key]['properties']:

                            all_args = all_args + prop + ', '

                        print(all_args)

    print('')
    print("Available keys %s" % str(all_keys))
Exemple #4
0
def main():
    parser = argparse.ArgumentParser()
    group = parser.add_argument_group("Actions")
    group.add_argument('action', help="backup/restore/deletes the object is selected on the --type flag",
                       choices=('backup', 'restore', 'delete'), metavar="backup | delete | restore --file FILE", nargs=1)

    parser.add_argument("-v", "--verbose", help="detailed logging.", action='store_true', required=False )
    group1 = parser.add_argument_group("Required")
    group1.add_argument("-t", "--type", help="specifies the type of the object [shares, export, quotas, schedules, policies, pools, all].",
                        action='store', required=True, choices=('shares', 'exports', 'quotas', 'schedules', 'policies', 'pools', 'all'), metavar='TYPE')
    group1.add_argument("-f", "--file", help="Path to the backup file for restore operation.", action='store', required=False)
    group1.add_argument("-u", "--username", help="Username for login.", action='store', required=True, dest='user')
    group1.add_argument("-pw", "--password", help="Password to login.", dest='password')
    group1.add_argument("-n", "--name", help="Cluster name to connect.", action='store', required=True, dest='clustername')
    args = parser.parse_args()
    
    password = args.password
    
    if "ISI_TOOLS_PASSWORD" in os.environ:
        password = os.environ["ISI_TOOLS_PASSWORD"]

    LOG_FILENAME = args.type + '.log'

    # Add the log message handler to the logger
    handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=52428800, backupCount=100)

    # create a logging format
    formatter = logging.Formatter('%(levelname)s %(asctime)s --> %(message)s')
    handler.setFormatter(formatter)
    my_logger.addHandler(handler)

    if not password:
        my_logger.error("--password (or ISI_TOOLS_PASSWORD environment variable) is required.")
        raise Syntax("--password (or ISI_TOOLS_PASSWORD environment variable) is required.")
    if args.action[0] == 'restore' and args.file == None:
        my_logger.error("--file is required in restore operation.")
        raise Syntax("--file is required in Restore operation.")
    if args.action[0] == 'restore' and args.type == 'all':
        my_logger.error("--type all is illegal with restore option.")
        raise Syntax("--type all is illegal with restore option.")
    if args.verbose:
        my_logger.setLevel('DEBUG')
    else:
        my_logger.setLevel('INFO')
    my_logger.info('------------------------------------- Isilon Tools -------------------------------------')
    api = isilon.API(args.clustername, args.user, password)
    if args.action[0] == 'backup':
        backup(api, args)
    elif args.action[0] == 'restore':
        restore(api, args)
    elif args.action[0] == 'delete':
        delete(api, args)
    my_logger.info("review "+LOG_FILENAME+" for more information.")
    def test_access_points(self):
        api = isilon.API(fqdn,user,password,secure=False)
        
        #create and get listing again
        api.namespace.dir_create(testfolder)
        api.namespace.accesspoint_create(name='test_accesspoint',path=testfolder)

        self.assertEqual( api.namespace.accesspoint()['test_accesspoint'], testfolder)
        
        #test acls
        acl = api.namespace.accesspoint_getacl('test_accesspoint')
        api.namespace.accesspoint_setacl(name='test_accesspoint',acl=acl)
        
        #cleanup
        api.namespace.accesspoint_delete('test_accesspoint')
 def test_file_creation(self):
     api = isilon.API(fqdn,user,password,secure=False)
     
     #Create some test files / folders
     api.namespace.dir_create(testfolder)
     self.assertTrue(api.namespace.is_dir(testfolder))
     
     for x in ('a','b'):
         subfolder = testfolder + '/' + x
         api.namespace.dir_create(subfolder)
         for y in range(1,10):
             api.namespace.file_create(subfolder + '/' + str(x) + str(y),"test_file")
     
     #namespace example
     dir_a = []
     dir_b = []
     
     gena = api.namespace.dir(testfolder + '/a', limit=2, sort='name', dir='ASC')
     genb = api.namespace.dir(testfolder + '/b', limit=2, sort='name',dir='DESC')
     while True:
         try:
             itema = gena.next()
             itemb = genb.next()
             dir_a.append(itema['name'])
             dir_b.append(itemb['name'])
         except StopIteration:
             break
             
     self.assertEqual(dir_a,[u'a1', u'a2', u'a3', u'a4', u'a5', u'a6', u'a7', u'a8', u'a9'])
     self.assertEqual(dir_b,[u'b9', u'b8', u'b7', u'b6', u'b5', u'b4', u'b3', u'b2', u'b1'])
     
     for x in ('a','b'):
         subfolder = testfolder + '/' + x
         for y in range(1,10):
             self.assertEqual(api.namespace.file(subfolder + '/' + str(x) + str(y)),"test_file")
             api.namespace.file_delete(subfolder + '/' + str(x) + str(y))
         
         api.namespace.dir_delete(subfolder)
 def test_snap_delete_all(self):
     api = isilon.API(fqdn,user,password,secure=False)
     self.assertRaises(IsilonLibraryError,api.platform.snapshot_delete,"")
 def test_empty_resumable_api_set(self):
     api = isilon.API(fqdn,user,password,secure=False)
     results = api.platform.hdfs_racks()
     self.assertEqual(len(results),0)
     for x in results:
         self.assertTrue(False)
 def test_snap_bad_query(self):
     api = isilon.API(fqdn,user,password,secure=False)
     if api.platform.snapshot("fakename123askksdfkasdfkas"):
         self.assertTrue(False)
 def test_bad_ssl_cert(self):
     api = isilon.API(fqdn,user,password)
     self.assertRaises(requests.exceptions.SSLError,api.session.connect)