How to use create_share method in lisa

Best Python code snippet using lisa_python

share_usage.py

Source:share_usage.py Github

copy

Full Screen

...26 def __init__(self, account):27 self.account = account28 def run_all_samples(self):29 self.service = self.account.create_file_service()30 self.create_share()31 self.delete_share()32 self.share_metadata() 33 self.share_properties()34 self.share_stats()35 self.share_exists()36 self.list_shares()37 # This method contains sleeps, so don't run by default38 # self.service_properties()39 def _get_share_reference(self, prefix='share'):40 return '{}{}'.format(prefix, str(uuid.uuid4()).replace('-', ''))41 def _create_share(self, prefix='share'):42 share_name = self._get_share_reference(prefix)43 self.service.create_share(share_name)44 return share_name45 def create_share(self):46 # Basic47 share_name1 = self._get_share_reference()48 created = self.service.create_share(share_name1) # True49 # Quota50 share_name2 = self._get_share_reference()51 created = self.service.create_share(share_name2, quota=1) # True52 # Metadata53 metadata = {'val1': 'foo', 'val2': 'blah'}54 share_name3 = self._get_share_reference()55 created = self.service.create_share(share_name3, metadata=metadata) # True56 # Fail on exist57 share_name4 = self._get_share_reference()58 created = self.service.create_share(share_name4) # True 59 created = self.service.create_share(share_name4) # False60 try:61 self.service.create_share(share_name4, fail_on_exist=True)62 except AzureConflictHttpError:63 pass64 self.service.delete_share(share_name1)65 self.service.delete_share(share_name2)66 self.service.delete_share(share_name3)67 self.service.delete_share(share_name4)68 def delete_share(self):69 # Basic70 share_name = self._create_share()71 deleted = self.service.delete_share(share_name) # True 72 # Fail not exist73 share_name = self._get_share_reference()74 deleted = self.service.delete_share(share_name) # False75 try:76 self.service.delete_share(share_name, fail_not_exist=True)77 except AzureMissingResourceHttpError:78 pass79 def share_metadata(self):80 share_name = self._create_share()81 metadata = {'val1': 'foo', 'val2': 'blah'}82 # Basic83 self.service.set_share_metadata(share_name, metadata=metadata)84 metadata = self.service.get_share_metadata(share_name) # metadata={'val1': 'foo', 'val2': 'blah'} 85 # Replaces values, does not merge86 metadata = {'new': 'val'}87 self.service.set_share_metadata(share_name, metadata=metadata)88 metadata = self.service.get_share_metadata(share_name) # metadata={'new': 'val'}89 # Capital letters90 metadata = {'NEW': 'VAL'}91 self.service.set_share_metadata(share_name, metadata=metadata)92 metadata = self.service.get_share_metadata(share_name) # metadata={'new': 'VAL'}93 # Clearing94 self.service.set_share_metadata(share_name)95 metadata = self.service.get_share_metadata(share_name) # metadata={}96 97 self.service.delete_share(share_name)98 def share_properties(self):99 share_name = self._create_share()100 metadata = {'val1': 'foo', 'val2': 'blah'}101 # Basic102 # Sets the share quota to 1 GB103 self.service.set_share_properties(share_name, 1)104 share = self.service.get_share_properties(share_name)105 quota = share.properties.quota # 1106 # Metadata107 self.service.set_share_metadata(share_name, metadata=metadata)108 share = self.service.get_share_properties(share_name)109 metadata = share.metadata # metadata={'val1': 'foo', 'val2': 'blah'}110 self.service.delete_share(share_name)111 def share_stats(self):112 share_name = self._create_share()113 self.service.create_file_from_text(share_name, None, 'file1', b'hello world')114 # Basic115 share_usage = self.service.get_share_stats(share_name) # 1116 self.service.delete_share(share_name)117 def share_exists(self):118 share_name = self._get_share_reference()119 # Basic120 exists = self.service.exists(share_name) # False121 self.service.create_share(share_name)122 exists = self.service.exists(share_name) # True123 self.service.delete_share(share_name)124 def list_shares(self):125 share_name1 = self._get_share_reference()126 self.service.create_share('share1', metadata={'val1': 'foo', 'val2': 'blah'})127 share_name2 = self._create_share('share2')128 share_name3 = self._create_share('thirdshare')129 # Basic130 # Commented out as this will list every share in your account131 # shares = list(self.service.list_shares())132 # for share in shares:133 # print(share.name) # share1, share2, thirdq, all other shares created in the service 134 # Num results135 # Will return in alphabetical order. 136 shares = list(self.service.list_shares(num_results=2))137 for share in shares:138 print(share.name) # share1, share2139 # Prefix140 shares = list(self.service.list_shares(prefix='share'))141 for share in shares:142 print(share.name) # share1, share2...

Full Screen

Full Screen

repo.py

Source:repo.py Github

copy

Full Screen

...6 def __init__(self):7 self.ints = {}8 def add(self, new_id, id1, id2, populate_to_siblings=False):9 share = (self.ints[id1] + self.ints[id2]) % Q10 self.create_share(new_id, share)11 if(populate_to_siblings):12 for s in self.siblings:13 s.add(new_id, id1, id2)14 return MPCNatural(new_id, self)15 def create_float(self, secret):16 return MPCFixedPoint(secret, self)17 def create_natural(self, secret):18 shares = self.share(secret)19 return self.create_natural_with_shares(shares)20 def create_natural_with_shares(self, shares):21 id = np.random.randint(0, 2**32)22 self.create_share(id, shares[0])23 self.siblings[0].create_share(id, shares[1])24 self.siblings[1].create_share(id, shares[2])25 return MPCNatural(id, self)26 def create_share(self, id, share):27 if(id not in self.ints.keys()):28 self.ints[id] = share29 return True # everything is good30 else:31 return False # hmm... non-unique int id32 def div_scalar(self, new_id, id1, scalar, populate_to_siblings=False):33 share = int(self.ints[id1] / scalar) % Q34 self.create_share(new_id, share)35 if(populate_to_siblings):36 for s in self.siblings:37 s.div_scalar(new_id, id1, scalar)38 return MPCNatural(new_id, self)39 def get_share(self, id):40 return self.ints[id]41 def mult(self, new_id, id1, id2, populate_to_siblings=False):42 z0 = self.mult_local(id1, id2)43 z1 = self.left.mult_local(id1, id2)44 z2 = self.right.mult_local(id1, id2)45 return z0 + z1 + z246 def mult_local(self, id1, id2):47 x_0 = self.ints[id1]48 y_0 = self.ints[id2]49 x_1 = self.left.ints[id1]50 y_1 = self.left.ints[id2]51 z0 = ((x_0 * y_0) + (x_0 * y_1) + (x_1 * y_0)) % Q52 return self.create_natural(z0)53 def mult_scalar(self, new_id, id1, scalar, populate_to_siblings=False):54 share = (self.ints[id1] * scalar) % Q55 self.create_share(new_id, share)56 if(populate_to_siblings):57 for s in self.siblings:58 s.mult_scalar(new_id, id1, scalar)59 return MPCNatural(new_id, self)60 def set_siblings(self, a, b):61 self.siblings = list()62 self.left = a63 self.right = b64 self.siblings.append(a)65 self.siblings.append(b)66 def share(self, secret):67 first = random.randrange(Q)68 second = random.randrange(Q)69 third = (secret - first - second) % Q70 return [first, second, third]71 def sub(self, new_id, id1, id2, populate_to_siblings=False):72 share = (self.ints[id1] - self.ints[id2]) % Q73 self.create_share(new_id, share)74 if(populate_to_siblings):75 for s in self.siblings:76 s.sub(new_id, id1, id2)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful