def __init__(self): if os.name == "nt": self.local_ip = socket.gethostbyname(socket.gethostname()) else: self.local_ip = get_ip_address('eth0') if self.local_ip == None or self.local_ip == "127.0.0.1": raise "ERROR: can't get an invalid IP address of your computer" self.fs_uid = demo_cfg.FS_UID self.fs_duration = '3600' # this is only used for Mac or Linux, Windows will allocate a driver automatically self.mount_path = '/var/tmp/bourne' self.__client_setup() self.bourne = Bourne() self.bourne.connect(demo_cfg.BOURNE_DATA_IPADDR, S3_PORT)
#---------------------------------------------------------------------- # command-line parsing #---------------------------------------------------------------------- try: bourne_ip = os.environ['BOURNE_IPADDR'] except: bourne_ip = 'localhost' try: bourne_data_ip = os.environ['BOURNE_DATA_IPADDR'] except: bourne_data_ip = bourne_ip bourne = Bourne() if len(sys.argv) <7 : print "usage python fileaccesssanity.py <api> <namespace> <keypool> <cos> <uid> <secret/password>" sys.exit(0) api = sys.argv[1] namespace = sys.argv[2] bucket = sys.argv[3] cos = sys.argv[4] uid = sys.argv[5] secret = sys.argv[6] if (len(sys.argv) == 8): preserveDirStructure = sys.argv[7] else:
class FileAccessDemo(object): def __init__(self): if os.name == "nt": self.local_ip = socket.gethostbyname(socket.gethostname()) else: self.local_ip = get_ip_address('eth0') if self.local_ip == None or self.local_ip == "127.0.0.1": raise "ERROR: can't get an invalid IP address of your computer" self.fs_uid = demo_cfg.FS_UID self.fs_duration = '3600' # this is only used for Mac or Linux, Windows will allocate a driver automatically self.mount_path = '/var/tmp/bourne' self.__client_setup() self.bourne = Bourne() self.bourne.connect(demo_cfg.BOURNE_DATA_IPADDR, S3_PORT) def __client_setup(self): # registry change to support mount if os.name == "nt": key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default', 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(key, "AnonymousUid", None, _winreg.REG_DWORD, int(demo_cfg.FS_UID)) _winreg.SetValueEx(key, "AnonymousGid", None, _winreg.REG_DWORD, int(demo_cfg.FS_UID)) _winreg.CloseKey(key) def enablefs(self, keypool, uid, secretKey): pass def disablefs(self, keypool, uid, secretKey): pass # wait until the mode is pesent def wait(self, keypool, mode, uid, secretKey): while True: response = self.bourne.bucket_switchget(self.namespace, keypool, uid, secretKey) if (response.status_code == 404 or response.status_code == 403): sys.stderr.write("Resource not found") sys.exit(1) h = response.headers if (h[FILE_ACCESS_MODE_HEADER] and h[FILE_ACCESS_MODE_HEADER].lower() == mode.lower()): return time.sleep(2) def domount(self, exportpoint): if os.name == "nt": cmd = "mount %s *" % exportpoint else: if (os.path.exists(self.mount_path) == False): os.makedirs(self.mount_path) cmd = "mount -t nfs %s %s" % (exportpoint, self.mount_path) process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) (out, err) = process.communicate() if process.returncode != 0: sys.stderr.write("ERROR: failed to mount %s" % (exportpoint)) sys.exit(1) if os.name == "nt": # Windows print a message to indicate where is mounted self.mount_path = os.path.join(out[0:2], os.path.sep) def dounmount(self): process = subprocess.Popen("mount", shell=True, stdout=subprocess.PIPE) (out, err) = process.communicate() if process.returncode != 0: sys.stderr.write("ERROR: failed to get mount list") sys.exit(1) #TODO: we just remove all mounts which have 'storageos' in the export path lines = out.splitlines() for line in lines: if os.name == 'nt': if line.find('storageos') >= 0: process = subprocess.Popen("umount %s" % line[0:2], shell=True, stdout=subprocess.PIPE) process.wait() if process.returncode != 0: sys.stderr.write("ERROR: failed to umount %s" % line[0:2]) else: if line.find(self.mount_path) >= 0: process = subprocess.Popen("umount %s" % self.mount_path, shell=True, stdout=subprocess.PIPE) process.wait() if process.returncode != 0: sys.stderr.write( "ERROR: failed to umount %s" % self.mount_path) def print_list(self, result): print '---------------objects path---------------------' objects = result['fileaccess_response']['objects'] if type(objects) == dict: objects = [objects] for obj in objects: relpath = obj['relativePath'] path = os.path.join(self.mount_path, relpath) wPath = path.replace("/", "\\") print "%s\t%s\t%s" % (obj['name'], wPath, obj['size'])
help='new password', default=None) update.add_argument('--groups', metavar='groups', help='groups for this uid', default=None) if __name__ == '__main__': try: if (len(sys.argv) > 1): cmd = sys.argv[1] else: parser.print_help() sys.exit(1) bourne = Bourne() if (cmd == "create"): args = create.parse_args() passwordgroup_create(args, bourne) elif (cmd == "update"): args = update.parse_args() passwordgroup_update(args, bourne) elif (cmd == "list"): args = parser.parse_args() passwordgroup_listgroup(args, bourne) elif (cmd == "remove"): args = parser.parse_args() passwordgroup_remove(args, bourne) else: parser.print_help()