def query_perf_counter(self, counter_id): """Retrieves counter information for the list of counter IDs passed in. counter_id [list]: list of integers containing the counter IDs. """ if counter_id: if not isinstance(counter_id, list): raise VIException("counter_id must be a list", FaultTypes.PARAMETER_ERROR) else: raise VIException("No counter_id specified.", FaultTypes.PARAMETER_ERROR) try: request = VI.QueryPerfCounterRequestMsg() mor_qpc = request.new__this(self._mor) mor_qpc.set_attribute_type(self._mor.get_attribute_type()) request.set_element__this(mor_qpc) request.set_element_counterId(counter_id) qpc = self._server._proxy.QueryPerfCounter(request)._returnval return qpc except (VI.ZSI.FaultException) as e: raise VIApiException(e)
def destroy(self, sync_run=True): """ Destroys this object, deleting its contents and removing it from its parent folder (if any) * sync_run: (default True), If False does not wait for the task to finish and returns an instance of a VITask for the user to monitor its progress """ try: request = VI.Destroy_TaskRequestMsg() _this = request.new__this(self._mor) _this.set_attribute_type(self._mor.get_attribute_type()) request.set_element__this(_this) task = self._server._proxy.Destroy_Task(request)._returnval vi_task = VITask(task, self._server) if sync_run: status = vi_task.wait_for_state( [vi_task.STATE_SUCCESS, vi_task.STATE_ERROR]) if status == vi_task.STATE_ERROR: raise VIException(vi_task.get_error_message(), FaultTypes.TASK_ERROR) return return vi_task except (VI.ZSI.FaultException) as e: raise VIApiException(e)
def rename(self, new_name, sync_run=True): """ Renames this managed entity. * new_name: Any / (slash), \ (backslash), character used in this name element will be escaped. Similarly, any % (percent) character used in this name element will be escaped, unless it is used to start an escape sequence. A slash is escaped as %2F or %2f. A backslash is escaped as %5C or %5c, and a percent is escaped as %25. * sync_run: (default True), If False does not wait for the task to finish and returns an instance of a VITask for the user to monitor its progress """ try: request = VI.Rename_TaskRequestMsg() _this = request.new__this(self._mor) _this.set_attribute_type(self._mor.get_attribute_type()) request.set_element__this(_this) request.set_element_newName(new_name) task = self._server._proxy.Rename_Task(request)._returnval vi_task = VITask(task, self._server) if sync_run: status = vi_task.wait_for_state( [vi_task.STATE_SUCCESS, vi_task.STATE_ERROR]) if status == vi_task.STATE_ERROR: raise VIException(vi_task.get_error_message(), FaultTypes.TASK_ERROR) return return vi_task except (VI.ZSI.FaultException) as e: raise VIApiException(e)
def query_perf_provider_summary(self, entity): """Returns a ProviderSummary object for a ManagedObject for which performance statistics can be queried. Also indicates whether current or summary statistics are supported. If the input managed entity is not a performance provider, an InvalidArgument exception is thrown. entity [mor]: The ManagedObject for which available performance metrics are queried. """ if not entity: raise VIException("No Entity specified.", FaultTypes.PARAMETER_ERROR) try: request = VI.QueryPerfProviderSummaryRequestMsg() mor_qpps = request.new__this(self._mor) mor_qpps.set_attribute_type(self._mor.get_attribute_type()) request.set_element__this(mor_qpps) qpps_entity = request.new_entity(entity) qpps_entity.set_attribute_type(entity.get_attribute_type()) request.set_element_entity(qpps_entity) qpps = self._server._proxy.QueryPerfProviderSummary( request)._returnval return qpps except (VI.ZSI.FaultException) as e: raise VIApiException(e)
def get_file(self, remote_path, local_path=None, overwrite="False"): if local_path is None: local_path = os.path.basename(remote_path) if os.path.exists(local_path) and not overwrite: raise VIException("Local file already exists", FaultTypes.PARAMETER_ERROR) resource_path = "/folder/%s" % remote_path.lstrip("/") request_url = self.__build_request_url(resource_path) if sys.version_info >= (2, 6): response = self.__send_request(request_url) chunk_size = 16 * 1024 with open(local_path, "wb") as fd: while True: chunk = response.read(chunk_size) if not chunk: break fd.write(chunk) return response.code == 200 else: # SSL protocol error when executing this on Python < 2.6 urllib.urlretrieve(request_url, local_path)
def query_perf(self, entity, format='normal', interval_id=None, max_sample=None, metric_id=None, start_time=None, composite=False): """Returns performance statistics for the entity. The client can limit the returned information by specifying a list of metrics and a suggested sample interval ID. Server accepts either the refreshRate or one of the historical intervals as input interval. entity [mor]: The ManagedObject managed object whose performance statistics are being queried. format [string]: The format to be used while returning the statistics. interval_id [int]: The interval (samplingPeriod) in seconds for which performance statistics are queried. There is a set of intervals for historical statistics. Refer HistoricalInterval for more more information about these intervals. To retrieve the greatest available level of detail, the provider's refreshRate may be used for this property. max_sample [int]: The maximum number of samples to be returned from server. The number of samples returned are more recent samples in the time range specified. For example, if the user specifies a maxSample of 1, but not a given time range, the most recent sample collected is returned. This parameter can be used only when querying for real-time statistics by setting the intervalId parameter to the provider's refreshRate. This argument is ignored for historical statistics. metric_id: [PerfMetricId]: The performance metrics to be retrieved. start_time [timetuple]: The time from which statistics are to be retrieved. Corresponds to server time. When startTime is omitted, the returned metrics start from the first available metric in the system. When a startTime is specified, the returned samples do not include the sample at startTime. composite: [bool]: If true requests QueryPerfComposite method instead of QuerPerf. """ if interval_id: if not isinstance(interval_id, int) or interval_id < 0: raise VIException("interval_id must be a positive integer", FaultTypes.PARAMETER_ERROR) if max_sample: if not isinstance(max_sample, int) or max_sample < 0: raise VIException("max_sample must be a positive integer", FaultTypes.PARAMETER_ERROR) if metric_id: if not isinstance(metric_id, list): raise VIException("metric_id must be a list of integers", FaultTypes.PARAMETER_ERROR) try: if composite: request = VI.QueryPerfCompositeRequestMsg() else: request = VI.QueryPerfRequestMsg() mor_qp = request.new__this(self._mor) mor_qp.set_attribute_type(self._mor.get_attribute_type()) request.set_element__this(mor_qp) query_spec = request.new_querySpec() spec_entity = query_spec.new_entity(entity) spec_entity.set_attribute_type(entity.get_attribute_type()) query_spec.set_element_entity(spec_entity) if format != "normal": if format == "csv": query_spec.set_element_format(format) else: raise VIException( "accepted formats are 'normal' and 'csv'", FaultTypes.PARAMETER_ERROR) if interval_id: query_spec.set_element_intervalId(interval_id) if max_sample: query_spec.set_element_maxSample(max_sample) if metric_id: query_spec.set_element_metricId(metric_id) if start_time: query_spec.set_element_startTime(start_time) if composite: request.set_element_querySpec(query_spec) query_perf = self._server._proxy.QueryPerfComposite( request)._returnval else: request.set_element_querySpec([query_spec]) query_perf = self._server._proxy.QueryPerf(request)._returnval return query_perf except (VI.ZSI.FaultException) as e: raise VIApiException(e)
def delete_file(self, remote_path): raise VIException("Operation not supported yet", FaultTypes.NOT_SUPPORTED)
def move_file(self, src_path, dst_path, overwrite=True): raise VIException("Operatoin not supported yet", FaultTypes.NOT_SUPPORTED)
def send_directory(self, local_path, remote_path, overwrite=True): raise VIException("Operation not supported yet", FaultTypes.NOT_SUPPORTED)
def create_directory(self, remote_path, create_parents=True): raise VIException("Operation not supported yet", FaultTypes.NOT_SUPPORTED)