output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Limit the spec to include only the related entries that are not in the database.
Explain what the following Python 3 code does def limit_spec(self, spec): if list(spec.keys()) == ['name']: # if we're just resolving on name, include other names return ((Q(name=spec['name']) | Q(other_names__name=spec['name'])) & Q(memberships__organization__jurisdi...
As a Python code composer, you craft elegant and concise scripts.
def validate(self): """ Error check model params. :raises TypeError: Throws TypeError if validation fails. """ if self.nregions is None: raise TypeError("neutral regions cannot be None") if self.sregions is None: raise TypeError("selected regions...
Implement a function in Python 3 to raise TypeError if validation fails.
As a python code expert, you are capable of creating scripts from specifications.
def _prepare_imports(self, dicts): """ an override for prepare imports that sorts the imports by parent_id dependencies """ # all pseudo parent ids we've seen pseudo_ids = set() # pseudo matches pseudo_matches = {} # get prepared imports from parent prepared = di...
Write a Python 3 script to prepare the imports for the organization.
You are a Python code architect, reviewing and designing scalable and efficient code
def evolvets(rng, pop, params, simplification_interval, recorder=None, suppress_table_indexing=False, record_gvalue_matrix=False, stopping_criterion=None, track_mutation_counts=False, remove_extinct_variants=True): """ Evolve a population with tree sequence recording ...
Create a Python 3 function to evolve a population with tree sequence recording.
You are a Python code generator, capable of creating scripts from specifications.
def exponential_size_change(Nstart, Nstop, time): """ Generate a list of population sizes according to exponential size_change model :param Nstart: population size at onset of size change :param Nstop: Population size to reach at end of size change :param time: Time (in generations) to get from...
Create a Python 3 function to generate a list of integers representing the number of times a given population size is in the range Nstart to Nstop.
As a Python code analyst, you investigate and solve complex coding mysteries
def split_sql(sql): """generate hunks of SQL that are between the bookends return: tuple of beginning bookend, closing bookend, and contents note: beginning & end of string are returned as None""" bookends = ("\n", ";", "--", "/*", "*/") last_bookend_found = None start = 0 while sta...
Can you implement a function in Python 3 that splits the SQL into a sequence of beginning bookend closing bookend and contents
As a Python code translator, you convert algorithms and pseudocode into Python.
def check_file(filename=None, show_filename=False, add_semicolon=False): """ Check whether an input file is valid PostgreSQL. If no filename is passed, STDIN is checked. Returns a status code: 0 if the input is valid, 1 if invalid. """ # either work with sys.stdin or open the file if filena...
Implement a function in Python 3 to check whether an input file is valid PostgreSQL.
As a Python code translator, you convert algorithms and pseudocode into Python.
def check_string(sql_string, add_semicolon=False): """ Check whether a string is valid PostgreSQL. Returns a boolean indicating validity and a message from ecpg, which will be an empty string if the input was valid, or a description of the problem otherwise. """ prepped_sql = sqlprep.prepare...
Write a Python 3 function that can check whether a string is valid PostgreSQL. Returns a boolean indicating validity and a message from ecpg.
As a Python code analyst, you investigate and solve complex coding mysteries
def check_syntax(string): """ Check syntax of a string of PostgreSQL-dialect SQL """ args = ["ecpg", "-o", "-", "-"] with open(os.devnull, "w") as devnull: try: proc = subprocess.Popen(args, shell=False, stdout=devnull, ...
Create a Python 3 function to check syntax of a string of PostgreSQL - dialect SQL
You are a Python code generator, capable of creating scripts from specifications.
def get_inventory(self, context): """ Will locate vm in vcenter and fill its uuid :type context: cloudshell.shell.core.context.ResourceCommandContext """ vcenter_vm_name = context.resource.attributes['vCenter VM'] vcenter_vm_name = vcenter_vm_name.replace('\\', '/') ...
How would you implement a function in Python 3 that gets the inventory for a given resource
You are a Python code architect, reviewing and designing scalable and efficient code
Get a list of virtual machine names that are available for this service instance
Can you generate a brief explanation for the following Python 3 code def get_snapshots(self, si, logger, vm_uuid): vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid) logger.info("Get snapshots") snapshots = SnapshotRetriever.get_vm_snapshots(vm) return snapshots.keys()
As a Python code analyst, you investigate and solve complex coding mysteries
def connect(self, address, user, password, port=443): """ Connect to vCenter via SSL and return SI object :param address: vCenter address (host / ip address) :param user: user name for authentication :param password:password for authentication :param port: ...
How would you code a function in Python 3 to connect to a vCenter via SSL and returns a vim. si. PyVmomi object.
You are a Python code generator, capable of creating scripts from specifications.
def find_datacenter_by_name(self, si, path, name): """ Finds datacenter in the vCenter or returns "None" :param si: pyvmomi 'ServiceInstance' :param path: the path to find the object ('dc' or 'dc/folder' or 'dc/folder/folder/etc...') :param name: the datacent...
How would you implement a function in Python 3 that finds datacenter in the vCenter or returns None
As a Python code analyst, you investigate and solve complex coding mysteries
def find_by_uuid(self, si, uuid, is_vm=True, path=None, data_center=None): """ Finds vm/host by his uuid in the vCenter or returns "None" :param si: pyvmomi 'ServiceInstance' :param uuid: the object uuid :param path: the path to find the object ('dc' or 'dc/f...
How would you implement a function in Python 3 that finds vm or host by uuid in the vCenter or returns None
As a Python code analyst, you investigate and solve complex coding mysteries
def find_host_by_name(self, si, path, name): """ Finds datastore in the vCenter or returns "None" :param si: pyvmomi 'ServiceInstance' :param path: the path to find the object ('dc' or 'dc/folder' or 'dc/folder/folder/etc...') :param name: the datastore name ...
Write a Python 3 function for finding datastore in the vCenter or returns None
As a Python code analyst, you investigate and solve complex coding mysteries
Finds datastore in the vCenter or returns None
How would you explain what the following Python 3 function does def find_datastore_by_name(self, si, path, name): return self.find_obj_by_path(si, path, name, self.Datastore)
You are a Python code architect, reviewing and designing scalable and efficient code
Finds the portgroup with the given name on the given dv switch
Given the following Python 3 function, write the documentation def find_portgroup(self, si, dv_switch_path, name): dv_switch = self.get_folder(si, dv_switch_path) if dv_switch and dv_switch.portgroup: for port in dv_switch.portgroup: if port.name == name: ...
You are a Python code architect, reviewing and designing scalable and efficient code
Finds the network in the vCenter or returns None
Can you generate the documentation for the following Python 3 function def find_network_by_name(self, si, path, name): return self.find_obj_by_path(si, path, name, self.Network)
As a python code expert, you are capable of creating scripts from specifications.
Finds vm in the vCenter or returns None
How would you explain what the following Python 3 function does def find_vm_by_name(self, si, path, name): return self.find_obj_by_path(si, path, name, self.VM)
As a Python code composer, you craft elegant and concise scripts.
Finds the object in the vCenter or returns None
Here you have a function in Python 3, explain what it does def find_obj_by_path(self, si, path, name, type_name): folder = self.get_folder(si, path) if folder is None: raise ValueError('vmomi managed object not found at: {0}'.format(path)) look_in = None if hasattr(folder, ...
As a Python code translator, you convert algorithms and pseudocode into Python.
def find_dvs_by_path(self,si ,path): """ Finds vm in the vCenter or returns "None" :param si: pyvmomi 'ServiceInstance' :param path: the path to find the object ('dc' or 'dc/folder' or 'dc/folder/folder/etc...') """ dvs = self.get_folder(si, path) i...
Write a Python 3 function that can find the virtual switch in the vCenter or returns None
As a Python code composer, you craft elegant and concise scripts.
Gets the folder in the vCenter or returns None
Here you have a function in Python 3, explain what it does def get_folder(self, si, path, root=None): search_index = si.content.searchIndex sub_folder = root if root else si.content.rootFolder if not path: return sub_folder paths = [p for p in path.split("/") if p] ...
You are a Python code analyst, evaluating scripts for potential improvements.
Find a network by a Full Name
Can you tell what is the following Python 3 function doing def get_network_by_full_name(self, si, default_network_full_name): path, name = get_path_and_name(default_network_full_name) return self.find_network_by_name(si, path, name) if name else None
As a Python code composer, you craft elegant and concise scripts.
Returns an object by name for a specific type
Can you tell what is the following Python 3 function doing def get_obj(self, content, vimtype, name): obj = None container = self._get_all_objects_by_type(content, vimtype) # If no name was given will return the first object from list of a objects matching the given vimtype type for c ...
You are a Python code analyst, evaluating scripts for potential improvements.
This method clones a VM from a template and returns the VM object or throws argument is not valid
Here you have a function in Python 3, explain what it does def clone_vm(self, clone_params, logger, cancellation_context): result = self.CloneVmResult() if not isinstance(clone_params.si, self.vim.ServiceInstance): result.error = 'si must be init as ServiceInstance' return resul...
As a Python code translator, you convert algorithms and pseudocode into Python.
destroy the given vm
Given the following Python 3 function, write the documentation def destroy_vm(self, vm, logger): self.power_off_before_destroy(logger, vm) logger.info(("Destroying VM {0}".format(vm.name))) task = vm.Destroy_Task() return self.task_waiter.wait_for_task(task=task, logger=logger, action...
As a Python code translator, you convert algorithms and pseudocode into Python.
def destroy_vm_by_name(self, si, vm_name, vm_path, logger): """ destroy the given vm :param si: pyvmomi 'ServiceInstance' :param vm_name: str name of the vm to destroyed :param vm_path: str path to the vm that will be destroyed :param logger: """ i...
Write a Python 3 script to destroy the given vm by name
You are a Python code analyst, evaluating scripts for potential improvements.
destroy the given vm by uuid
Make a summary of the following Python 3 code def destroy_vm_by_uuid(self, si, vm_uuid, vm_path, logger): if vm_uuid is not None: vm = self.find_by_uuid(si, vm_uuid, vm_path) if vm: return self.destroy_vm(vm, logger) # return 'vm not found' # for apply the...
You are a Python code architect, reviewing and designing scalable and efficient code
Create Task for VM re - configure
How would you explain what the following Python 3 function does def vm_reconfig_task(vm, device_change): config_spec = vim.vm.ConfigSpec(deviceChange=device_change) task = vm.ReconfigVM_Task(config_spec) return task
As a python code expert, you are capable of creating scripts from specifications.
Try to find a Network in VM by name.
Make a summary of the following Python 3 code def vm_get_network_by_name(vm, network_name): # return None for network in vm.network: if hasattr(network, "name") and network_name == network.name: return network return None
As a Python code composer, you craft elegant and concise scripts.
def get_vm_full_path(self, si, vm): """ :param vm: vim.VirtualMachine :return: """ folder_name = None folder = vm.parent if folder: folder_name = folder.name folder_parent = folder.parent while folder_parent and folder_parent....
Write a Python 3 function for returning the full path to the VM
You are a Python code architect, reviewing and designing scalable and efficient code
def load_vm_uuid_by_name(self, si, vcenter_data_model, vm_name): """ Returns the vm uuid :param si: Service instance to the vcenter :param vcenter_data_model: vcenter data model :param vm_name: the vm name :return: str uuid """ path = VMLocation.combine([v...
Can you write a function in Python 3 where it returns the vm uuid by name
You are a Python code generator, capable of creating scripts from specifications.
def power_off(self, si, logger, session, vcenter_data_model, vm_uuid, resource_fullname): """ Power off of a vm :param vcenter_data_model: vcenter model :param si: Service Instance :param logger: :param session: :param vcenter_data_model: vcenter_data_model ...
Implement a function in Python 3 to power off a VM
You are a Python code analyst, evaluating scripts for potential improvements.
def power_on(self, si, logger, session, vm_uuid, resource_fullname): """ power on the specified vm :param si: :param logger: :param session: :param vm_uuid: the uuid of the vm :param resource_fullname: the full name of the deployed app resource :return: ...
Can you write a function in Python 3 where it powers on the specified vm
You are a Python code analyst, evaluating scripts for potential improvements.
def create_logger_for_context(self, logger_name, context): """ Create QS Logger for command context AutoLoadCommandContext or ResourceCommandContext :param logger_name: :type logger_name: str :param context: :return: """ if self._is_instance_of(context, '...
Write a Python 3 function for creating a QS Logger for the given command context.
You are a Python code analyst, evaluating scripts for potential improvements.
def connect_to_networks(self, si, logger, vm_uuid, vm_network_mappings, default_network_name, reserved_networks, dv_switch_name, promiscuous_mode): """ Connect VM to Network :param si: VmWare Service Instance - defined connection to vCenter :param logger: ...
Write a Python 3 function that can connect VM to Network
You are a Python code architect, reviewing and designing scalable and efficient code
Maps the requests to the available vnic and returns a dictionary of the mappings.
Can you generate the documentation for the following Python 3 function def map_request_to_vnics(self, requests, vnics, existing_network, default_network, reserved_networks): mapping = dict() reserved_networks = reserved_networks if reserved_networks else [] vnics_to_network_mapping = self._map_...
As a Python code composer, you craft elegant and concise scripts.
def deploy_image(self, vcenter_data_model, image_params, logger): """ Receives ovf image parameters and deploy it on the designated vcenter :param VMwarevCenterResourceModel vcenter_data_model: :type image_params: vCenterShell.vm.ovf_image_params.OvfImageParams :param logger: ...
Write a Python 3 script for receiving ovf image parameters and deploy it on the designated vcenter :param VMwarevCenterResourceModel vcenter_data_model: :type image_params: vCenterShell.vm.ovf_image_params.OvfImageParams :param logger:
As a python code expert, you are capable of creating scripts from specifications.
Build the list of arguments to use for the ovf tool.
Can you generate a brief explanation for the following Python 3 code def _get_args(self, ovf_tool_exe_path, image_params, logger): # create vm name vm_name_param = VM_NAME_PARAM.format(image_params.vm_name) # datastore name datastore_param = DATA_STORE_PARAM.format(image_params.datastor...
You are a Python code generator, capable of creating scripts from specifications.
Executes a command with a connection to the vCenter service.
Can you generate the documentation for the following Python 3 function def execute_command_with_connection(self, context, command, *args): logger = self.context_based_logger_factory.create_logger_for_context( logger_name='vCenterShell', context=context) if not command: ...
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns True if the connection details has changed.
Given the following Python 3 function, write the documentation def has_connection_details_changed(self, req_connection_details): if self.connection_details is None and req_connection_details is None: return False if self.connection_details is None or req_connection_details is None: ...
You are a Python code analyst, evaluating scripts for potential improvements.
def restore_snapshot(self, si, logger, session, vm_uuid, resource_fullname, snapshot_name): """ Restores a virtual machine to a snapshot :param vim.ServiceInstance si: py_vmomi service instance :param logger: Logger :param session: CloudShellAPISession :type session: clou...
Implement a function in Python 3 to restore a virtual machine to a snapshot
You are a Python code analyst, evaluating scripts for potential improvements.
Returns a snapshot object by its name
Explain what the following Python 3 code does def _get_snapshot(vm, snapshot_name): snapshots = SnapshotRetriever.get_vm_snapshots(vm) if snapshot_name not in snapshots: raise SnapshotNotFoundException('Snapshot {0} was not found'.format(snapshot_name)) return snapshots[snapshot_na...
As a Python code composer, you craft elegant and concise scripts.
This formula is used for the 1980 table.
Here you have a function in Python 3, explain what it does def formula_1980(household, period, parameters): ''' To compute this allowance, the 'rent' value must be provided for the same month, but 'housing_occupancy_status' is not necessary. ''' return household('rent', period) * paramet...
You are a Python code generator, capable of creating scripts from specifications.
A formula that returns True if the person s pension depends on their birth date.
How would you explain what the following Python 3 function does def formula(person, period, parameters): ''' A person's pension depends on their birth date. In French: retraite selon l'âge. In Arabic: تقاعد. ''' age_condition = person('age', period) >= parameters(period)....
As a python code expert, you are capable of creating scripts from specifications.
Serializes output as JSON and writes it to console output wrapped with special prefix and suffix
Given the following Python 3 function, write the documentation def set_command_result(result, unpicklable=False): # we do not need to serialize an empty response from the vCenter if result is None: return if isinstance(result, basestring): return result json = jsonpickle.encode(result,...
As a python code expert, you are capable of creating scripts from specifications.
Validate and discover the current AutoLoad details.
Can you generate a brief explanation for the following Python 3 code def validate_and_discover(self, context): logger = self._get_logger(context) logger.info('Autodiscovery started') si = None resource = None with CloudShellSessionContext(context) as cloudshell_session: ...
As a Python code composer, you craft elegant and concise scripts.
def _make_attributes_slash_backslash_agnostic(attributes_with_slash_or_backslash): """ :param attributes_with_slash_or_backslash: resource attributes from cloudshell.cp.vcenter.models.QualiDriverModels.ResourceContextDetails :type attributes_with_slash_or_backslash: dict[str,str] ...
How would you implement a function in Python 3 that converts back slashes to front slashes.
As a python code expert, you are capable of creating scripts from specifications.
def save_sandbox(self, context, save_actions, cancellation_context): """ Save sandbox command, persists an artifact of existing VMs, from which new vms can be restored :param ResourceCommandContext context: :param list[SaveApp] save_actions: :param CancellationContext cancellatio...
Write a Python 3 script to save sandbox command, persists an artifact of existing VMs, from which new vms can be restored :param ResourceCommandContext context: :param list[SaveApp] save_actions: :param CancellationContext cancellation_context: :return: list[SaveAppResult] save_app_results
As a python code expert, you are capable of creating scripts from specifications.
Delete a saved sandbox along with any vms associated with it
Make a summary of the following Python 3 code def delete_saved_sandbox(self, context, delete_saved_apps, cancellation_context): connection = self.command_wrapper.execute_command_with_connection(context, self.delete_saved_sandbox_command.d...
As a Python code composer, you craft elegant and concise scripts.
def deploy_from_template(self, context, deploy_action, cancellation_context): """ Deploy From Template Command, will deploy vm from template :param CancellationContext cancellation_context: :param ResourceCommandContext context: the context of the command :param DeployApp deploy...
Can you write a function in Python 3 where it deploys From Template Command, will deploy vm from template :param CancellationContext cancellation_context: :param ResourceCommandContext context: the context of the command :param DeployApp deploy_action: :return DeployAppResult deploy results
You are a Python code generator, capable of creating scripts from specifications.
def deploy_clone_from_vm(self, context, deploy_action, cancellation_context): """ Deploy Cloned VM From VM Command, will deploy vm from template :param CancellationContext cancellation_context: :param ResourceCommandContext context: the context of the command :param DeployApp de...
Create a Python 3 function to deploy Cloned VM From VM Command, will deploy vm from template :param CancellationContext cancellation_context: :param ResourceCommandContext context: the context of the command :param DeployApp deploy_action: :return DeployAppResult deploy results
You are a Python code architect, reviewing and designing scalable and efficient code
This method will deploy vm from linked clone from template
Can you generate a brief explanation for the following Python 3 code def deploy_from_linked_clone(self, context, deploy_action, cancellation_context): linked_clone_from_vm_model = self.resource_model_parser.convert_to_resource_model( attributes=deploy_action.actionParams.deployment.attributes, ...
As a python code expert, you are capable of creating scripts from specifications.
This method will deploy vm from ovf image
Can you generate the documentation for the following Python 3 function def deploy_from_image(self, context, deploy_action, cancellation_context): deploy_action.actionParams.deployment.attributes['vCenter Name'] = context.resource.name deploy_from_image_model = self.resource_model_parser.convert_to_resou...
You are a Python code architect, reviewing and designing scalable and efficient code
This command will assign all the vnics on the default network to the default network and will the disconnect all the vnics on the default network
Here you have a function in Python 3, explain what it does def disconnect_all(self, context, ports): resource_details = self._parse_remote_model(context) # execute command res = self.command_wrapper.execute_command_with_connection( context, self.virtual_switch_disconnect...
As a python code expert, you are capable of creating scripts from specifications.
Delete Instance Command will only destroy the vm and will not remove the resource
Here you have a function in Python 3, explain what it does def DeleteInstance(self, context, ports): resource_details = self._parse_remote_model(context) # execute command res = self.command_wrapper.execute_command_with_connection( context, self.destroy_virtual_machine_co...
As a Python code translator, you convert algorithms and pseudocode into Python.
Refresh the ip of the resource
Given the following Python 3 function, write the documentation def refresh_ip(self, context, cancellation_context, ports): resource_details = self._parse_remote_model(context) # execute command res = self.command_wrapper.execute_command_with_connection(context, ...
As a Python code composer, you craft elegant and concise scripts.
Power off the remote vm
How would you explain what the following Python 3 function does def power_off(self, context, ports): return self._power_command(context, ports, self.vm_power_management_command.power_off)
You are a Python code analyst, evaluating scripts for potential improvements.
def power_on(self, context, ports): """ Powers on the remote vm :param models.QualiDriverModels.ResourceRemoteCommandContext context: the context the command runs on :param list[string] ports: the ports of the connection between the remote resource and the local resource, NOT IN USE!!! ...
Write a Python 3 script for powering on the remote vm
You are a Python code architect, reviewing and designing scalable and efficient code
def power_cycle(self, context, ports, delay): """ preforms a restart to the vm :param models.QualiDriverModels.ResourceRemoteCommandContext context: the context the command runs on :param list[string] ports: the ports of the connection between the remote resource and the local resource, ...
Write a Python 3 script to power cycle the VM on the given ports
You are a Python code architect, reviewing and designing scalable and efficient code
parse the remote resource model and adds its full name
How would you explain what the following Python 3 function does def _parse_remote_model(self, context): if not context.remote_endpoints: raise Exception('no remote resources found in context: {0}', jsonpickle.encode(context, unpicklable=False)) resource = context.remote_endpoints[0] ...
You are a Python code architect, reviewing and designing scalable and efficient code
def save_snapshot(self, context, snapshot_name, save_memory='No'): """ Saves virtual machine to a snapshot :param context: resource context of the vCenterShell :type context: models.QualiDriverModels.ResourceCommandContext :param snapshot_name: snapshot name to save to :t...
Write a Python 3 function for saving a snapshot of the virtual machine to a snapshot
You are a Python code analyst, evaluating scripts for potential improvements.
def restore_snapshot(self, context, snapshot_name): """ Restores virtual machine from a snapshot :param context: resource context of the vCenterShell :type context: models.QualiDriverModels.ResourceCommandContext :param snapshot_name: snapshot name to save to :type snapsh...
Write a Python 3 script to restore virtual machine from a snapshot
You are a Python code generator, capable of creating scripts from specifications.
def get_snapshots(self, context): """ Returns list of snapshots :param context: resource context of the vCenterShell :type context: models.QualiDriverModels.ResourceCommandContext :return: """ resource_details = self._parse_remote_model(context) res = self...
Create a Python 3 function to return list of snapshots for the current resource
You are a Python code analyst, evaluating scripts for potential improvements.
Creates a snapshot with a unique name and returns a SavedResults object
Make a summary of the following Python 3 code def orchestration_save(self, context, mode="shallow", custom_params=None): resource_details = self._parse_remote_model(context) created_date = datetime.now() snapshot_name = created_date.strftime('%y_%m_%d %H_%M_%S_%f') created_snapshot_path ...
As a Python code composer, you craft elegant and concise scripts.
Returns a VMwarevCenterResourceModel object from the API.
Here you have a function in Python 3, explain what it does def get_vcenter_data_model(self, api, vcenter_name): if not vcenter_name: raise ValueError('VMWare vCenter name is empty') vcenter_instance = api.GetResourceDetails(vcenter_name) vcenter_resource_model = self.resource_model_p...
As a Python code translator, you convert algorithms and pseudocode into Python.
def back_slash_to_front_converter(string): """ Replacing all \ in the str to / :param string: single string to modify :type string: str """ try: if not string or not isinstance(string, str): return string return string.replace('\\', '/') except Exception: ...
Implement a function in Python 3 to convert back slashes to front slashes
You are a Python code analyst, evaluating scripts for potential improvements.
def get_object_as_string(obj): """ Converts any object to JSON-like readable format, ready to be printed for debugging purposes :param obj: Any object :return: string """ if isinstance(obj, str): return obj if isinstance(obj, list): return '\r\n\;'.join([get_object_as_string(...
Write a Python 3 script for converting any object to JSON - like readable format ready to be printed for debugging purposes
As a Python code analyst, you investigate and solve complex coding mysteries
def get_path_and_name(full_name): """ Split Whole Patch onto 'Patch' and 'Name' :param full_name: <str> Full Resource Name - likes 'Root/Folder/Folder2/Name' :return: tuple (Patch, Name) """ if full_name: parts = full_name.split("/") return ("/".join(parts[0:-1]), parts[-1]) if l...
Write a Python 3 function for splitting Whole Patch onto Patch and Name
As a python code expert, you are capable of creating scripts from specifications.
def get_details(self): """ :rtype list[VmDataField] """ data = [] if self.deployment == 'vCenter Clone VM From VM': data.append(VmDetailsProperty(key='Cloned VM Name',value= self.dep_attributes.get('vCenter VM',''))) if self.deployment == 'VCenter De...
Write a Python 3 script for returning details of the virtual machine
You are a Python code generator, capable of creating scripts from specifications.
Sets the vcenter parameters if not already set at the deployment option
Make a summary of the following Python 3 code def set_deplyment_vcenter_params(vcenter_resource_model, deploy_params): # Override attributes deploy_params.vm_cluster = deploy_params.vm_cluster or vcenter_resource_model.vm_cluster deploy_params.vm_storage = deploy_params.vm_storage or vcenter_res...
You are a Python code architect, reviewing and designing scalable and efficient code
def remote_save_snapshot(self, context, ports, snapshot_name, save_memory): """ Saves virtual machine to a snapshot :param context: resource context of the vCenterShell :type context: models.QualiDriverModels.ResourceCommandContext :param ports:list[string] ports: the ports of th...
Write a Python 3 function for saving a snapshot of the virtual machine to a snapshot
As a Python code translator, you convert algorithms and pseudocode into Python.
Restores virtual machine from a snapshot
Can you generate a brief explanation for the following Python 3 code def remote_restore_snapshot(self, context, ports, snapshot_name): return self.command_orchestrator.restore_snapshot(context, snapshot_name)
You are a Python code generator, capable of creating scripts from specifications.
def connect_bulk(self, si, logger, vcenter_data_model, request): """ :param si: :param logger: :param VMwarevCenterResourceModel vcenter_data_model: :param request: :return: """ self.logger = logger self.logger.info('Apply connectivity changes has...
How would you implement a function in Python 3 that connects to a single virtual machine.
You are a Python code architect, reviewing and designing scalable and efficient code
def destroy(self, si, logger, session, vcenter_data_model, vm_uuid, vm_name, reservation_id): """ :param si: :param logger: :param CloudShellAPISession session: :param vcenter_data_model: :param vm_uuid: :param str vm_name: This is the resource name :param...
Create a Python 3 function for destroying the resource with the given uuid
As a python code expert, you are capable of creating scripts from specifications.
def _disconnect_all_my_connectors(session, resource_name, reservation_id, logger): """ :param CloudShellAPISession session: :param str resource_name: :param str reservation_id: """ reservation_details = session.GetReservationDetails(reservation_id) connectors = re...
Can you write a function in Python 3 where it disconnects all connectors in a reservation.
As a Python code composer, you craft elegant and concise scripts.
def delete_sandbox(self, si, logger, vcenter_data_model, delete_sandbox_actions, cancellation_context): """ Deletes a saved sandbox's artifacts :param vcenter_data_model: VMwarevCenterResourceModel :param vim.ServiceInstance si: py_vmomi service instance :type si: vim.ServiceIns...
Can you create a Python 3 function that deletes a saved sandbox.
You are a Python code analyst, evaluating scripts for potential improvements.
def execute_deploy_from_linked_clone(self, si, logger, vcenter_data_model, reservation_id, deployment_params, cancellation_context, folder_manager): """ Calls the deployer to deploy vm from snapshot :param cancellation_context: :param str reservation_id: :param si: :param...
Implement a function in Python 3 to execute the deployer to deploy vm from linked clone
As a Python code translator, you convert algorithms and pseudocode into Python.
Executes the deploy_clone_from_vm method
How would you explain what the following Python 3 function does def execute_deploy_clone_from_vm(self, si, logger, vcenter_data_model, reservation_id, deployment_params, cancellation_context, folder_manager): self._prepare_deployed_apps_folder(deployment_params, si, logger, folder_manager, vcenter_data_model) ...
You are a Python code architect, reviewing and designing scalable and efficient code
Creates a snapshot of the current state of the virtual machine
Explain what the following Python 3 code does def save_snapshot(self, si, logger, vm_uuid, snapshot_name, save_memory): vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid) snapshot_path_to_be_created = SaveSnapshotCommand._get_snapshot_name_to_be_created(snapshot_name, vm) save_vm_memory_to_sn...
As a Python code analyst, you investigate and solve complex coding mysteries
Create a snapshot of the virtual machine.
Given the following Python 3 function, write the documentation def _create_snapshot(logger, snapshot_name, vm, save_vm_memory_to_snapshot): logger.info("Create virtual machine snapshot") dump_memory = save_vm_memory_to_snapshot quiesce = True task = vm.CreateSnapshot(snapshot_name, 'Crea...
You are a Python code analyst, evaluating scripts for potential improvements.
def generate_unique_name(name_prefix, reservation_id=None): """ Generate a unique name. Method generate a guid and adds the first 8 characteres of the new guid to 'name_prefix'. If reservation id is provided than the first 4 chars of the generated guid are taken and the last 4 of the reservation id ...
Create a Python 3 function to generate a unique name.
You are a Python code generator, capable of creating scripts from specifications.
Disconnects the specified network from the specified virtual machine.
Can you generate a brief explanation for the following Python 3 code def disconnect(self, si, logger, vcenter_data_model, vm_uuid, network_name=None, vm=None): logger.debug("Disconnect Interface VM: '{0}' Network: '{1}' ...".format(vm_uuid, network_name or "ALL")) if vm is None: vm = self.py...
As a Python code composer, you craft elegant and concise scripts.
Removes interfaces from VM
Can you tell what is the following Python 3 function doing def remove_interfaces_from_vm_task(self, virtual_machine, filter_function=None): device_change = [] for device in virtual_machine.config.hardware.device: if isinstance(device, vim.vm.device.VirtualEthernetCard) and \ ...
As a Python code translator, you convert algorithms and pseudocode into Python.
Connects the given mapping to the given virtual machine and returns the virtual machine s entry point.
How would you explain what the following Python 3 function does def connect_by_mapping(self, si, vm, mapping, default_network, reserved_networks, logger, promiscuous_mode): request_mapping = [] logger.debug( 'about to map to the vm: {0}, the following networks'.format(vm.name if vm.name els...
You are a Python code analyst, evaluating scripts for potential improvements.
This function creates a Task which can be used to create a Distributed Virtual Portgroup.
Given the following Python 3 function, write the documentation def dv_port_group_create_task(dv_port_name, dv_switch, spec, vlan_id, logger, promiscuous_mode, num_ports=32): dv_pg_spec = vim.dvs.DistributedVirtualPortgroup.ConfigSpec() dv_pg_spec.name = dv_port_name dv_pg_spec.numPorts = num_po...
You are a Python code architect, reviewing and designing scalable and efficient code
def create_deployment_details(vcenter_resource_model, vm_cluster, vm_storage, vm_resource_pool, vm_location): """ :type vcenter_resource_model: VMwarevCenterResourceModel :type vm_cluster: str :type vm_storage: str :type vm_resource_pool: str :type vm_location: str ...
Can you create a Python 3 function that creates a DeploymentDetails object from the given VMwarevCenterResourceModel.
You are a Python code architect, reviewing and designing scalable and efficient code
Refreshes the IP address of a virtual machine and updates Address property on the resource
How would you explain what the following Python 3 function does def refresh_ip(self, si, logger, session, vcenter_data_model, resource_model, cancellation_context, app_request_json): """ Refreshes IP address of virtual machine and updates Address property on the resource :par...
As a Python code analyst, you investigate and solve complex coding mysteries
Method retrieves the connection details from the vcenter resource model attributes.
Explain what the following Python 3 code does def get_connection_details(session, vcenter_resource_model, resource_context): session = session resource_context = resource_context # get vCenter connection details from vCenter resource user = vcenter_resource_model.user vcenter_u...
As a python code expert, you are capable of creating scripts from specifications.
Add new vNIC to VM
Given the following Python 3 function, write the documentation def vnic_add_to_vm_task(nicspec, virtual_machine, logger): if issubclass(type(nicspec), vim.vm.device.VirtualDeviceSpec): nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add VNicService.vnic_set_connectivity_sta...
As a Python code composer, you craft elegant and concise scripts.
def get_network_by_device(vm, device, pyvmomi_service, logger): """ Get a Network connected to a particular Device (vNIC) @see https://github.com/vmware/pyvmomi/blob/master/docs/vim/dvs/PortConnection.rst :param vm: :param device: <vim.vm.device.VirtualVmxnet3> instance of adapt...
Implement a Python 3 function for getting a Network connected to a particular Device
As a python code expert, you are capable of creating scripts from specifications.
Checks if the device is attached to the right network name.
How would you explain what the following Python 3 function does def device_is_attached_to_network(device, network_name): try: backing = device.backing except: return False if hasattr(backing, 'network') and hasattr(backing.network, 'name'): return network_name...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns a vNIC with an empty vNIC.
Make a summary of the following Python 3 code def vnic_compose_empty(device=None): nicspec = vim.vm.device.VirtualDeviceSpec() if device: nicspec.device = device nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit else: nicspec.operation = vim....
You are a Python code generator, capable of creating scripts from specifications.
def vnic_attach_to_network_standard(nicspec, network, logger): """ Attach vNIC to a 'usual' network :param nicspec: <vim.vm.device.VirtualDeviceSpec> :param network: <vim.Network> :param logger: :return: updated 'nicspec' """ if nicspec and network_is_stan...
Implement a Python 3 function for attaching vNIC to a standard network
You are a Python code generator, capable of creating scripts from specifications.
def vnic_attach_to_network_distributed(nicspec, port_group, logger): """ Attach vNIC to a Distributed Port Group network :param nicspec: <vim.vm.device.VirtualDeviceSpec> :param port_group: <vim.dvs.DistributedVirtualPortgroup> :param logger: :return: updated 'nicspec' ...
How would you code a function in Python 3 to attach vNIC to a Distributed Port Group
As a Python code composer, you craft elegant and concise scripts.
Attach vNIC to a network.
Here you have a function in Python 3, explain what it does def vnic_attached_to_network(nicspec, network, logger): if nicspec: if network_is_portgroup(network): return VNicService.vnic_attach_to_network_distributed(nicspec, network, ...
As a Python code composer, you craft elegant and concise scripts.
Compose new vNIC and attach it to VM & connect to Network
Given the following Python 3 function, write the documentation def vnic_add_new_to_vm_task(vm, network, logger): nicspes = VNicService.vnic_new_attached_to_network(network) task = VNicService.vnic_add_to_vm_task(nicspes, vm, logger) return task
As a Python code composer, you craft elegant and concise scripts.
def map_vnics(vm): """ maps the vnic on the vm by name :param vm: virtual machine :return: dictionary: {'vnic_name': vnic} """ return {device.deviceInfo.label: device for device in vm.config.hardware.device if isinstance(device, vim.vm.devi...
Can you implement a function in Python 3 that maps the vnic on the vm by name
You are a Python code architect, reviewing and designing scalable and efficient code
This function creates the device change spec and returns it
Given the following Python 3 function, write the documentation def get_device_spec(vnic, set_connected): nic_spec = VNicService.create_vnic_spec(vnic) VNicService.set_vnic_connectivity_status(nic_spec, to_connect=set_connected) return nic_spec
As a Python code composer, you craft elegant and concise scripts.
def create_vnic_spec(device): """ create device spec for existing device and the mode of edit for the vcenter to update :param device: :rtype: device spec """ nic_spec = vim.vm.device.VirtualDeviceSpec() nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operati...
Can you create a Python 3 function that creates a vnic spec for existing device
You are a Python code architect, reviewing and designing scalable and efficient code