Example #1
0
    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)
Example #2
0
    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 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 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 query_available_perf_metric(self,
                                    entity,
                                    begin_time=None,
                                    end_time=None,
                                    interval_id=None):
        """Retrieves available performance metrics for the specified
        ManagedObject between the optional beginTime and endTime. These are the
        performance statistics that are available for the given time interval.
        entity [mor]: The ManagedObject for which available performance metrics
            are queried.
        begin_time [time tuple]: The time from which available performance 
            metrics are gathered. Corresponds to server time. When the beginTime
            is omitted, the returned metrics start from the first available
            metric in the system.
        end_time [time tuple]: The time up to which available performance
            metrics are gathered. Corresponds to server time. When the endTime
            is omitted, the returned result includes up to the most recent
            metric value.
        interval_id [int]: Specify a particular interval that the query is
            interested in. Acceptable intervals are the refreshRate returned in
            QueryProviderSummary, which is used to retrieve available metrics
            for real-time performance statistics, or one of the historical
            intervals, which are used to retrieve available metrics for
            historical performance statistics. If interval is not specified,
            system returns available metrics for historical statistics.
        """
        if begin_time:
            begin_time[6] = 0

        if end_time:
            end_time[6] = 0
        try:
            request = VI.QueryAvailablePerfMetricRequestMsg()
            mor_pm = request.new__this(self._mor)
            mor_pm.set_attribute_type(self._mor.get_attribute_type())
            request.set_element__this(mor_pm)

            mor_entity = request.new_entity(entity)
            mor_entity.set_attribute_type(entity.get_attribute_type())
            request.set_element_entity(mor_entity)

            if begin_time:
                request.set_element_beginTime(begin_time)
            if end_time:
                request.set_element_endTime(end_time)
            if interval_id:
                request.set_element_intervalId(interval_id)

            do_perf_metric_id = self._server._proxy.QueryAvailablePerfMetric(
                request)._returnval
            return do_perf_metric_id

        except (VI.ZSI.FaultException) as e:
            raise VIApiException(e)
Example #6
0
 def reload(self):
     """
     Reload the entity state.
     Clients only need to call this method if they changed some external
     state that affects the service without using the Web service interface
     to perform the change. For example, hand-editing a virtual machine 
     configuration file affects the configuration of the associated virtual
     machine but the service managing the virtual machine might not monitor
     the file for changes. In this case, after such an edit, a client would
     call "reload" on the associated virtual machine to ensure the service
     and its clients have current data for the virtual machine.
     """
     try:
         request = VI.ReloadRequestMsg()
         _this = request.new__this(self._mor)
         _this.set_attribute_type(self._mor.get_attribute_type())
         request.set_element__this(_this)
         self._server._proxy.Reload(request)
     except (VI.ZSI.FaultException) as e:
         raise VIApiException(e)
Example #7
0
 def reconfigure(self, spec_content, sync=True):
     try:
         request = VI.ReconfigVM_TaskRequestMsg()
         _this = request.new__this(self.vm._mor)
         _this.set_attribute_type(self.vm._mor.get_attribute_type())
         request.set_element__this(_this)
         spec = request.new_spec()
         spec.set_element_bootOptions(spec_content)
         request.set_element_spec(spec)
         task = self.vm._server._proxy.ReconfigVM_Task(request)._returnval
         vi_task = VITask(task, self.vm._server)
         if sync:
             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), e:
         raise VIApiException(e)
    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)