def metadata_and_properties(self, service): share_name = 'sharename' + self.random_data.get_random_name(6) try: # All directories and share must be created in a parent share. # Max capacity: 5TB per share print('1. Create sample share with name ' + share_name) quota = 1 # in GB metadata = { "foo": "bar", "baz": "foo" } share_client = service.create_share(share_name=share_name) print('Sample share "'+ share_name +'" created.') print('2. Get share properties.') properties = share_client.get_share_properties() print('3. Get share metadata.') get_metadata = properties['metadata'] for k, v in get_metadata.items(): print("\t" + k + ": " + v) dir_name = 'dirname' + self.random_data.get_random_name(6) print('4. Create sample directory with name ' + dir_name) metadata = { "abc": "def", "jkl": "mno" } directory_client = share_client.create_directory(dir_name, metadata=metadata) print('Sample directory "'+ dir_name +'" created.') print('5. Get directory properties.') properties = directory_client.get_directory_properties() print('6. Get directory metadata.') get_metadata = properties['metadata'] for k, v in get_metadata.items(): print("\t" + k + ": " + v) file_name = 'sample.txt' # Uploading text to share_name/dir_name/sample.txt in Azure Files account. # Max capacity: 1TB per file print('7. Upload sample file from text to directory.') metadata = { "prop1": "val1", "prop2": "val2" } file_client = directory_client.get_file_client(file_name) file_client.upload_file('Hello World! - from text sample', metadata=metadata) print('Sample file "' + file_name + '" created and uploaded to: ' + share_name + '/' + dir_name) print('8. Get file properties.') properties = file_client.get_file_properties() print('9. Get file metadata.') get_metadata = properties['metadata'] for k, v in get_metadata.items(): print("\t" + k + ": " + v) # This is for demo purposes, all files will be deleted when share is deleted print('10. Delete file.') file_client.delete_file() # This is for demo purposes, all directories will be deleted when share is deleted print('11. Delete directory.') directory_client.delete_directory() finally: print('12. Delete share.') share_client.delete_share(share_name) print("Metadata and properties sample completed")