def verify_vault(self): ''' check the vault name exist or not. ''' try: self.vault = Vault.get_vault_by_name(self.api, self.vault_name) except ValueError: self.vault = Vault.create_vault(self.api, self.vault_name)
def verify_vault(self): """ check the vault name exist or not. """ try: self.vault = Vault.get_vault_by_name(self.api, self.vault_name) except ValueError: self.vault = Vault.create_vault(self.api, self.vault_name)
def upload_to_aliyun_oas(file_path, desc=None): """ 上传文件到阿里云归档存储服务器(oss) :param file_path: 文件路径名 :param desc: 归档文件的描述 :return: 文件归档id """ if not os.path.exists(file_path): raise Exception('file is not exist: {file_path}'.format(file_path=file_path)) start_time = time.time() desc = desc if desc else os.path.basename(file_path) api = OASAPI(__aliyun__.get('oas_server'), __aliyun__.get('access_key'), __aliyun__.get('access_secret')) vault = Vault.create_vault(api, __aliyun__.get('oas_vault')) if not os.path.isfile(file_path): raise Exception("file is not exist [file]".format(file=file_path)) size = os.path.getsize(file_path) if size < (200 * 1024 * 1024): archive_id = vault.upload_archive(file_path, desc) else: uploader = vault.initiate_uploader(file_path, desc) archive_id = uploader.start() use_time = math.floor(time.time() - start_time) message = "upload file to aliyun oas [{file_name}], use seconds: {second}s".format(file_name=file_path, second=use_time) write_log(message) return archive_id
def initOas(self): '''initialize oas api''' api = OASAPI(self.oasConf['server_host'], self.oasConf['access_key_id'], self.oasConf['access_key_secret']) self.__vault = Vault.get_vault_by_id(api, self.vaultConf['vault_id'])
#_*_coding:utf-8_*_ # check the python SDK for more explanations if needed # file management of aliyun's Archive Storage from oas.oas_api import OASAPI from oas.ease.vault import Vault server = 'cn-shenzhen.oas.aliyuncs.com' key_id = 'Rfh4U5ZcodMCHIDV' key_secret = 'mtWkRREAzh0T66kr7E7rMYv4J4xfxI' api = OASAPI(server, key_id, key_secret) #vault = Vault.create_vault(api, 'backup') vault = Vault.get_vault_by_name(api, 'backup') # upload archive #archive_id = vault.upload_archive('/Users/ou/archive-2016-08-06.tar.gz',desc='Macbook Air backup, archive-2016-08-06.tar.gz') # get archive list job = vault.retrieve_inventory() job.download_to_file('archives.txt') # download archive #job = vault.retrieve_archive('B0FBAF06FFCF5EF16ADB3871BD24DDEA5AD41662E8FA4BA09D50A9FA590F8E2D6D8EC297780B49C5EA3E61EA4CFFD7775BDAAF7FC7B4C4582B6D1A501C6A2F0B') #job.download_to_file('input.tar.gz')