Best Python code snippet using localstack_python
nfs3.py
Source:nfs3.py
...16 "The nfs3 execution module failed to load: the showmount binary is not in"17 " the path.",18 )19 return True20def list_exports(exports="/etc/exports"):21 """22 List configured exports23 CLI Example:24 .. code-block:: bash25 salt '*' nfs.list_exports26 """27 ret = {}28 with salt.utils.files.fopen(exports, "r") as efl:29 for line in salt.utils.stringutils.to_unicode(efl.read()).splitlines():30 if not line:31 continue32 if line.startswith("#"):33 continue34 comps = line.split()35 # Handle the case where the same path is given twice36 if not comps[0] in ret:37 ret[comps[0]] = []38 newshares = []39 for perm in comps[1:]:40 if perm.startswith("/"):41 newshares.append(perm)42 continue43 permcomps = perm.split("(")44 permcomps[1] = permcomps[1].replace(")", "")45 hosts = permcomps[0]46 if not isinstance(hosts, str):47 # Lists, etc would silently mangle /etc/exports48 raise TypeError("hosts argument must be a string")49 options = permcomps[1].split(",")50 ret[comps[0]].append({"hosts": hosts, "options": options})51 for share in newshares:52 ret[share] = ret[comps[0]]53 return ret54def del_export(exports="/etc/exports", path=None):55 """56 Remove an export57 CLI Example:58 .. code-block:: bash59 salt '*' nfs.del_export /media/storage60 """61 edict = list_exports(exports)62 del edict[path]63 _write_exports(exports, edict)64 return edict65def add_export(exports="/etc/exports", path=None, hosts=None, options=None):66 """67 Add an export68 CLI Example:69 .. code-block:: bash70 salt '*' nfs3.add_export path='/srv/test' hosts='127.0.0.1' options=['rw']71 """72 if options is None:73 options = []74 if not isinstance(hosts, str):75 # Lists, etc would silently mangle /etc/exports76 raise TypeError("hosts argument must be a string")77 edict = list_exports(exports)78 if path not in edict:79 edict[path] = []80 new = {"hosts": hosts, "options": options}81 edict[path].append(new)82 _write_exports(exports, edict)83 return new84def _write_exports(exports, edict):85 """86 Write an exports file to disk87 If multiple shares were initially configured per line, like:88 /media/storage /media/data *(ro,sync,no_subtree_check)89 ...then they will be saved to disk with only one share per line:90 /media/storage *(ro,sync,no_subtree_check)91 /media/data *(ro,sync,no_subtree_check)...
cloudformation_exports_info.py
Source:cloudformation_exports_info.py
...41 from botocore.exceptions import BotoCoreError42except ImportError:43 pass # handled by AnsibleAWSModule44@AWSRetry.exponential_backoff()45def list_exports(cloudformation_client):46 '''Get Exports Names and Values and return in dictionary '''47 list_exports_paginator = cloudformation_client.get_paginator('list_exports')48 exports = list_exports_paginator.paginate().build_full_result()['Exports']49 export_items = dict()50 for item in exports:51 export_items[item['Name']] = item['Value']52 return export_items53def main():54 argument_spec = dict()55 result = dict(56 changed=False,57 original_message=''58 )59 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=False)60 cloudformation_client = module.client('cloudformation')61 try:62 result['export_items'] = list_exports(cloudformation_client)63 except (ClientError, BotoCoreError) as e:64 module.fail_json_aws(e)65 result.update()66 module.exit_json(**result)67if __name__ == '__main__':...
index.py
Source:index.py
...14 self.response.set_data('Name', self._name)15 @property16 def id(self):17 return "{}:{}:{}".format(self._region, self._name, self._value)18 def list_exports(self, next_token=None):19 ret = None20 if next_token:21 ret = self._cfn.list_exports(NextToken=next_token)22 else:23 ret = self._cfn.list_exports()24 l = ret['Exports']25 if 'NextToken' in ret:26 l.extend(self.list_exports(next_token=ret['NextToken']))27 return l28 def get_value(self):29 exports = self.list_exports()30 try:31 value = list(filter(lambda x: x["Name"] == self._name, exports))[0]["Value"]32 return value33 except Exception:34 raise NotFoundError(self._name)35 def value(self):36 self._value = self.get_value()37 self.response.physical_resource_id = self.id38 self.response.set_data('Value', self._value)39 def create(self, policies):40 self.value()41 def update(self, policies):42 self.value()43 def delete(self, policies):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!