Best Python code snippet using yandex-tank
vmware_content_library_info.py
Source:vmware_content_library_info.py
1#!/usr/bin/python2# -*- coding: utf-8 -*-3# Copyright: (c) 2019, Ansible Project4# Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com>5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)6from __future__ import absolute_import, division, print_function7__metaclass__ = type8ANSIBLE_METADATA = {9 'metadata_version': '1.1',10 'status': ['preview'],11 'supported_by': 'community'12}13DOCUMENTATION = r'''14---15module: vmware_content_library_info16short_description: Gather information about VMWare Content Library17description:18- Module to list the content libraries.19- Module to get information about specific content library.20- Content Library feature is introduced in vSphere 6.0 version, so this module is not supported in the earlier versions of vSphere.21- All variables and VMware object names are case sensitive.22author:23- Pavan Bidkar (@pgbidkar)24notes:25- Tested on vSphere 6.5, 6.726requirements:27- python >= 2.628- PyVmomi29- vSphere Automation SDK30options:31 library_id:32 description:33 - content library id for which details needs to be fetched.34 type: str35 required: False36extends_documentation_fragment:37- community.vmware.vmware_rest_client.documentation38'''39EXAMPLES = r'''40- name: Get List of Content Libraries41 vmware_content_library_info:42 hostname: '{{ vcenter_hostname }}'43 username: '{{ vcenter_username }}'44 password: '{{ vcenter_password }}'45 delegate_to: localhost46- name: Get information about content library47 vmware_content_library_info:48 hostname: '{{ vcenter_hostname }}'49 username: '{{ vcenter_username }}'50 password: '{{ vcenter_password }}'51 library_id: '13b0f060-f4d3-4f84-b61f-0fe1b0c0a5a8'52 validate_certs: no53 delegate_to: localhost54'''55RETURN = r'''56content_lib_details:57 description: list of content library metadata58 returned: on success59 type: list60 sample: [61 {62 "library_creation_time": "2019-07-02T11:50:52.242000",63 "library_description": "new description",64 "library_id": "13b0f060-f4d3-4f84-b61f-0fe1b0c0a5a8",65 "library_name": "demo-local-lib",66 "library_publish_info": {67 "authentication_method": "NONE",68 "persist_json_enabled": false,69 "publish_url": null,70 "published": false,71 "user_name": null72 },73 "library_server_guid": "0fd5813b-aac7-4b92-9fb7-f18f16565613",74 "library_type": "LOCAL",75 "library_version": "3"76 }77 ]78content_libs:79 description: list of content libraries80 returned: on success81 type: list82 sample: [83 "ded9c4d5-0dcd-4837-b1d8-af7398511e33",84 "36b72549-14ed-4b5f-94cb-6213fecacc02"85 ]86'''87from ansible.module_utils.basic import AnsibleModule88from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient89class VmwareContentLibInfo(VmwareRestClient):90 def __init__(self, module):91 """Constructor."""92 super(VmwareContentLibInfo, self).__init__(module)93 self.content_service = self.api_client94 self.library_info = []95 def get_all_content_libs(self):96 """Method to retrieve List of content libraries."""97 self.module.exit_json(changed=False, content_libs=self.content_service.content.LocalLibrary.list())98 def get_content_lib_details(self, library_id):99 """Method to retrieve Details of contentlib with library_id"""100 try:101 lib_details = self.content_service.content.LocalLibrary.get(library_id)102 except Exception as e:103 self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))104 lib_publish_info = dict(105 persist_json_enabled=lib_details.publish_info.persist_json_enabled,106 authentication_method=lib_details.publish_info.authentication_method,107 publish_url=lib_details.publish_info.publish_url,108 published=lib_details.publish_info.published,109 user_name=lib_details.publish_info.user_name110 )111 self.library_info.append(112 dict(113 library_name=lib_details.name,114 library_description=lib_details.description,115 library_id=lib_details.id,116 library_type=lib_details.type,117 library_creation_time=lib_details.creation_time,118 library_server_guid=lib_details.server_guid,119 library_version=lib_details.version,120 library_publish_info=lib_publish_info121 )122 )123 self.module.exit_json(exists=False, changed=False, content_lib_details=self.library_info)124def main():125 argument_spec = VmwareRestClient.vmware_client_argument_spec()126 argument_spec.update(127 library_id=dict(type='str', required=False),128 )129 module = AnsibleModule(argument_spec=argument_spec,130 supports_check_mode=True)131 vmware_contentlib_info = VmwareContentLibInfo(module)132 if module.params.get('library_id'):133 vmware_contentlib_info.get_content_lib_details(module.params['library_id'])134 else:135 vmware_contentlib_info.get_all_content_libs()136if __name__ == '__main__':...
fbcreator.py
Source:fbcreator.py
1import xml.etree.ElementTree as xml2class FbCreator(object):3 def create_fb2(self, config):4 self._config = config5 self._add_root_element()6 self._add_description_element()7 self._add_body_element()8 return xml.tostring(self._root, encoding='UTF-8', method='xml')9 def _add_root_element(self):10 self._root = xml.Element('FictionBook')11 self._root.attrib['xmlns'] = 'http://www.gribuser.ru/xml/fictionbook/2.0'12 self._root.attrib['xmlns:l'] = 'http://www.w3.org/1999/xlink'13 def _add_description_element(self):14 description = xml.SubElement(self._root, 'description')15 title_info = xml.SubElement(description, 'title-info')16 genre = xml.SubElement(title_info, 'genre')17 genre.text = self._config['genre']18 author = xml.SubElement(title_info, 'author')19 first_name = xml.SubElement(author, 'first-name')20 first_name.text = self._config['author']21 xml.SubElement(author, 'last-name')22 identifier = xml.SubElement(author, 'id')23 identifier.text = self._config['authorId']24 book_title = xml.SubElement(title_info, 'book-title')25 book_title.text = self._config['bookTitle']26 annotation = xml.SubElement(title_info, 'annotation')27 annotation_content = xml.SubElement(annotation, 'p')28 annotation_content.text = self._config['annotation']29 date = xml.SubElement(title_info, 'date')30 date.attrib['value'] = '2004-01-01'31 date.text = '2004'32 lang = xml.SubElement(title_info, 'lang')33 lang.text = 'ru'34 sequence = xml.SubElement(title_info, 'sequence')35 sequence.attrib['name'] = '_SEQUENCE'36 sequence.attrib['number'] = '777'37 xml.SubElement(description, 'document-info')38 publish_info = xml.SubElement(description, 'publish-info')39 xml.SubElement(publish_info, 'book-name')40 xml.SubElement(publish_info, 'publisher')41 xml.SubElement(publish_info, 'city')42 xml.SubElement(publish_info, 'year')43 xml.SubElement(publish_info, 'isbn')44 xml.SubElement(publish_info, 'sequence')45 def _add_body_element(self):46 body = xml.SubElement(self._root, 'body')47 title = xml.SubElement(body, 'title')48 title_content = xml.SubElement(title, 'p')49 title_content.text = self._config['bookTitle']50 for section in self._config['content']:51 self._add_section_to_body(body, section)52 def _add_section_to_body(self, body_element, section_data):53 section = xml.SubElement(body_element, 'section')54 section_title = xml.SubElement(section, 'title')55 section_title_content = xml.SubElement(section_title, 'p')56 section_title_content.text = section_data['title']57 for item in section_data['content']:58 section_content = xml.SubElement(section, 'p')...
publish_task.py
Source:publish_task.py
...15 device_ids.append(time_task.get('deviceIntID'))16 devices_info = await get_devices_info(device_ids)17 for time_task in due_tasks:18 device_info = devices_info[time_task.get('deviceIntID')]19 _info = await build_device_publish_info(time_task, device_info)20 publish_info.append(_info)21 task_result = await devices_publish(publish_info=publish_info)...
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!!