Commits

Anonymous committed 313132f

Added rename, reload, and destroy methods to VIManagedEntity

git-svn-id: https://pysphere.googlecode.com/svn/trunk@8493908643-0a7e-a946-f69b-c8c46af5c9d1

  • Participants
  • Parent commits 186f95e

Comments (0)

Files changed (6)

+Roadmap for 0.1.8
+- Added VIManagedEntity class extended by VIVirtualMachine
+- Added Rename, Reload, and Destroy methods to VIManagedEntity
 
-New in 0.1.5:
+New in 0.1.7
 
-- suppor vSphere 5.0
-- added suspend method to VM
-- added quick vm properties for disks and files info
-- implemented VIProperty to access vm objects properties as defined in vSphere API reference
-- Fixed error in get registered vms triggered on empty hosts or with faulty vms
-- Fixed '..' in import statements for compatibility with python 2.4
-- Added VM guest operations: create/delete/rename files and directories, upload/download files, start/stop/list processes
-- FIxed bugs in performance manager
-- FIxes issue in ZSI triggered when parsing dates prior to year 1970
+- Advanced filters parameter in VIServer.get_registered_vms
+- Set connection sockets timeout (works only since python 2.6)
+- added support for historical metrics in performance manager
+- Add get_api_type method to VIServer
+- Changes in ZSI framework to ease portability to python 3
+- Allow to clone from snapshot, shared disks, and select destination datastore
+- Add set_extra_settings method to VIVirtualMachine to configure advanced key-value options
+- Added VITaskHistoryCollector class, to navigate through tasks objects in vCenter servers
+- Added optional host parameter to VIVirtualMachine.clone method
+- Added relocate() method to VIVirtualMachine (by Chris Dituri)
+- Several fixes
 
 New in 0.1.6
 
 - Added VIMor class
 - Multithread support
 
-New in 0.1.7
+New in 0.1.5:
 
-- Advanced filters parameter in VIServer.get_registered_vms
-- Set connection sockets timeout (works only since python 2.6)
-- added support for historical metrics in performance manager
-- Add get_api_type method to VIServer
-- Changes in ZSI framework to ease portability to python 3
-- Allow to clone from snapshot, shared disks, and select destination datastore
-- Add set_extra_settings method to VIVirtualMachine to configure advanced key-value options
-- Added VITaskHistoryCollector class, to navigate through tasks objects in vCenter servers
-- Added optional host parameter to VIVirtualMachine.clone method
-- Added relocate() method to VIVirtualMachine (by Chris Dituri)
-- Several fixes
+- suppor vSphere 5.0
+- added suspend method to VM
+- added quick vm properties for disks and files info
+- implemented VIProperty to access vm objects properties as defined in vSphere API reference
+- Fixed error in get registered vms triggered on empty hosts or with faulty vms
+- Fixed '..' in import statements for compatibility with python 2.4
+- Added VM guest operations: create/delete/rename files and directories, upload/download files, start/stop/list processes
+- FIxed bugs in performance manager
+- FIxes issue in ZSI triggered when parsing dates prior to year 1970
 Discussion Group
 ----------------
 
-You can find many more examples and use cases in the `discussion group`_
+You can find a lot more examples and use cases in the `discussion group`_
 
 .. _discussion group: http://groups.google.com/group/pysphere
 

File pysphere/version.py

-# Do not edit. Auto generated
+# Do not edit. Auto generated
 version = (0, 1, 7)

File pysphere/vi_managed_entity.py

+#--
+# Copyright (c) 2012, Sebastian Tello
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   * Redistributions of source code must retain the above copyright notice,
+#     this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright notice,
+#     this list of conditions and the following disclaimer in the documentation
+#     and/or other materials provided with the distribution.
+#   * Neither the name of copyright holders nor the names of its contributors
+#     may be used to endorse or promote products derived from this software
+#     without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#--
+
+from pysphere.resources import VimService_services as VI
+from pysphere.vi_task import VITask
+from pysphere.resources.vi_exception import VIException, VIApiException, \
+                                            FaultTypes
+
+class VIManagedEntity(object):
+
+    def __init__(self, server, mor):
+        self._server = server
+        self._mor = mor
+        
+    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), e:
+            raise VIApiException(e)
+        
+    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), 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), e:
+            raise VIApiException(e)

File pysphere/vi_virtual_machine.py

 import os
 
 from pysphere.resources import VimService_services as VI
-from pysphere import VIException, VIApiException, FaultTypes
-from pysphere import VITask, VIProperty, VIMor, MORTypes
+from pysphere import VIProperty, VIMor, MORTypes
+from pysphere.vi_task import VITask
+from pysphere.resources.vi_exception import VIException, VIApiException, \
+                                            FaultTypes
 from pysphere.vi_snapshot import VISnapshot
+from pysphere.vi_managed_entity import VIManagedEntity
 
-class VIVirtualMachine:
+class VIVirtualMachine(VIManagedEntity):
 
     def __init__(self, server, mor):
-        self._server = server
-        self._mor = mor
+        VIManagedEntity.__init__(self, server, mor)
         self._root_snapshots = []
         self._snapshot_list = []
         self._disks = []
         author="Sebastian Tello",
         author_email="argos83@gmail.com",
         url="http://pysphere.googlecode.com",
-        download_url="http://pysphere.googlecode.com/files/pysphere-0.1.5.zip",
+        download_url="http://pysphere.googlecode.com/files/pysphere-0.1.7.zip",
         keywords = ["vSphere", "Virtual", "vmware", "ESX", "ESXi",
                     "VirtualCenter", "SDK", "API"],
         classifiers = [