opennebula 3.9.80.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +202 -0
 - data/NOTICE +47 -0
 - data/lib/opennebula.rb +58 -0
 - data/lib/opennebula/acl.rb +266 -0
 - data/lib/opennebula/acl_pool.rb +55 -0
 - data/lib/opennebula/client.rb +119 -0
 - data/lib/opennebula/cluster.rb +249 -0
 - data/lib/opennebula/cluster_pool.rb +58 -0
 - data/lib/opennebula/datastore.rb +171 -0
 - data/lib/opennebula/datastore_pool.rb +55 -0
 - data/lib/opennebula/document.rb +261 -0
 - data/lib/opennebula/document_json.rb +131 -0
 - data/lib/opennebula/document_pool.rb +102 -0
 - data/lib/opennebula/document_pool_json.rb +58 -0
 - data/lib/opennebula/error.rb +52 -0
 - data/lib/opennebula/group.rb +163 -0
 - data/lib/opennebula/group_pool.rb +56 -0
 - data/lib/opennebula/host.rb +201 -0
 - data/lib/opennebula/host_pool.rb +93 -0
 - data/lib/opennebula/image.rb +297 -0
 - data/lib/opennebula/image_pool.rb +79 -0
 - data/lib/opennebula/ldap_auth.rb +99 -0
 - data/lib/opennebula/ldap_auth_spec.rb +70 -0
 - data/lib/opennebula/pool.rb +160 -0
 - data/lib/opennebula/pool_element.rb +269 -0
 - data/lib/opennebula/server_cipher_auth.rb +148 -0
 - data/lib/opennebula/server_x509_auth.rb +104 -0
 - data/lib/opennebula/ssh_auth.rb +139 -0
 - data/lib/opennebula/system.rb +141 -0
 - data/lib/opennebula/template.rb +213 -0
 - data/lib/opennebula/template_pool.rb +79 -0
 - data/lib/opennebula/user.rb +174 -0
 - data/lib/opennebula/user_pool.rb +55 -0
 - data/lib/opennebula/virtual_machine.rb +560 -0
 - data/lib/opennebula/virtual_machine_pool.rb +323 -0
 - data/lib/opennebula/virtual_network.rb +249 -0
 - data/lib/opennebula/virtual_network_pool.rb +79 -0
 - data/lib/opennebula/x509_auth.rb +288 -0
 - data/lib/opennebula/xml_element.rb +427 -0
 - data/lib/opennebula/xml_pool.rb +45 -0
 - data/lib/opennebula/xml_utils.rb +34 -0
 - metadata +118 -0
 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -------------------------------------------------------------------------- #
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs        #
         
     | 
| 
      
 3 
     | 
    
         
            +
            #                                                                            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License"); you may    #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # not use this file except in compliance with the License. You may obtain    #
         
     | 
| 
      
 6 
     | 
    
         
            +
            # a copy of the License at                                                   #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #                                                                            #
         
     | 
| 
      
 8 
     | 
    
         
            +
            # http://www.apache.org/licenses/LICENSE-2.0                                 #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #                                                                            #
         
     | 
| 
      
 10 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software        #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,          #
         
     | 
| 
      
 12 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
         
     | 
| 
      
 13 
     | 
    
         
            +
            # See the License for the specific language governing permissions and        #
         
     | 
| 
      
 14 
     | 
    
         
            +
            # limitations under the License.                                             #
         
     | 
| 
      
 15 
     | 
    
         
            +
            #--------------------------------------------------------------------------- #
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            require 'opennebula/pool'
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            module OpenNebula
         
     | 
| 
      
 21 
     | 
    
         
            +
                class UserPool < Pool
         
     | 
| 
      
 22 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 23 
     | 
    
         
            +
                    # Constants and Class attribute accessors
         
     | 
| 
      
 24 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    USER_POOL_METHODS = {
         
     | 
| 
      
 27 
     | 
    
         
            +
                        :info => "userpool.info"
         
     | 
| 
      
 28 
     | 
    
         
            +
                    }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 31 
     | 
    
         
            +
                    # Class constructor & Pool Methods
         
     | 
| 
      
 32 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    # +client+ a Client object that represents a XML-RPC connection
         
     | 
| 
      
 35 
     | 
    
         
            +
                    def initialize(client)
         
     | 
| 
      
 36 
     | 
    
         
            +
                        super('USER_POOL','USER',client)
         
     | 
| 
      
 37 
     | 
    
         
            +
                    end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    # Factory method to create User objects
         
     | 
| 
      
 40 
     | 
    
         
            +
                    def factory(element_xml)
         
     | 
| 
      
 41 
     | 
    
         
            +
                        OpenNebula::User.new(element_xml,@client)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 45 
     | 
    
         
            +
                    # XML-RPC Methods for the User Object
         
     | 
| 
      
 46 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    # Retrieves all the Users in the pool.
         
     | 
| 
      
 49 
     | 
    
         
            +
                    def info()
         
     | 
| 
      
 50 
     | 
    
         
            +
                        super(USER_POOL_METHODS[:info])
         
     | 
| 
      
 51 
     | 
    
         
            +
                    end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                    alias_method :info!, :info
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,560 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -------------------------------------------------------------------------- #
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs        #
         
     | 
| 
      
 3 
     | 
    
         
            +
            #                                                                            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License"); you may    #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # not use this file except in compliance with the License. You may obtain    #
         
     | 
| 
      
 6 
     | 
    
         
            +
            # a copy of the License at                                                   #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #                                                                            #
         
     | 
| 
      
 8 
     | 
    
         
            +
            # http://www.apache.org/licenses/LICENSE-2.0                                 #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #                                                                            #
         
     | 
| 
      
 10 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software        #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,          #
         
     | 
| 
      
 12 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
         
     | 
| 
      
 13 
     | 
    
         
            +
            # See the License for the specific language governing permissions and        #
         
     | 
| 
      
 14 
     | 
    
         
            +
            # limitations under the License.                                             #
         
     | 
| 
      
 15 
     | 
    
         
            +
            #--------------------------------------------------------------------------- #
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            require 'opennebula/pool_element'
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            module OpenNebula
         
     | 
| 
      
 21 
     | 
    
         
            +
                class VirtualMachine < PoolElement
         
     | 
| 
      
 22 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 23 
     | 
    
         
            +
                    # Constants and Class Methods
         
     | 
| 
      
 24 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    VM_METHODS = {
         
     | 
| 
      
 27 
     | 
    
         
            +
                        :info       => "vm.info",
         
     | 
| 
      
 28 
     | 
    
         
            +
                        :allocate   => "vm.allocate",
         
     | 
| 
      
 29 
     | 
    
         
            +
                        :action     => "vm.action",
         
     | 
| 
      
 30 
     | 
    
         
            +
                        :migrate    => "vm.migrate",
         
     | 
| 
      
 31 
     | 
    
         
            +
                        :deploy     => "vm.deploy",
         
     | 
| 
      
 32 
     | 
    
         
            +
                        :savedisk   => "vm.savedisk",
         
     | 
| 
      
 33 
     | 
    
         
            +
                        :chown      => "vm.chown",
         
     | 
| 
      
 34 
     | 
    
         
            +
                        :chmod      => "vm.chmod",
         
     | 
| 
      
 35 
     | 
    
         
            +
                        :monitoring => "vm.monitoring",
         
     | 
| 
      
 36 
     | 
    
         
            +
                        :attach     => "vm.attach",
         
     | 
| 
      
 37 
     | 
    
         
            +
                        :detach     => "vm.detach",
         
     | 
| 
      
 38 
     | 
    
         
            +
                        :rename     => "vm.rename",
         
     | 
| 
      
 39 
     | 
    
         
            +
                        :update     => "vm.update",
         
     | 
| 
      
 40 
     | 
    
         
            +
                        :resize     => "vm.resize",
         
     | 
| 
      
 41 
     | 
    
         
            +
                        :snapshotcreate => "vm.snapshotcreate",
         
     | 
| 
      
 42 
     | 
    
         
            +
                        :snapshotrevert => "vm.snapshotrevert",
         
     | 
| 
      
 43 
     | 
    
         
            +
                        :snapshotdelete => "vm.snapshotdelete",
         
     | 
| 
      
 44 
     | 
    
         
            +
                        :attachnic  => "vm.attachnic",
         
     | 
| 
      
 45 
     | 
    
         
            +
                        :detachnic  => "vm.detachnic",
         
     | 
| 
      
 46 
     | 
    
         
            +
                        :resize     => "vm.resize"
         
     | 
| 
      
 47 
     | 
    
         
            +
                    }
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                    VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED
         
     | 
| 
      
 50 
     | 
    
         
            +
                        POWEROFF}
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                    LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND
         
     | 
| 
      
 53 
     | 
    
         
            +
                        SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG
         
     | 
| 
      
 54 
     | 
    
         
            +
                        SHUTDOWN CANCEL FAILURE CLEANUP_RESUBMIT UNKNOWN HOTPLUG SHUTDOWN_POWEROFF
         
     | 
| 
      
 55 
     | 
    
         
            +
                        BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED CLEANUP_DELETE
         
     | 
| 
      
 56 
     | 
    
         
            +
                        HOTPLUG_SNAPSHOT HOTPLUG_NIC HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF
         
     | 
| 
      
 57 
     | 
    
         
            +
                        HOTPLUG_SAVEAS_SUSPENDED}
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    SHORT_VM_STATES={
         
     | 
| 
      
 60 
     | 
    
         
            +
                        "INIT"      => "init",
         
     | 
| 
      
 61 
     | 
    
         
            +
                        "PENDING"   => "pend",
         
     | 
| 
      
 62 
     | 
    
         
            +
                        "HOLD"      => "hold",
         
     | 
| 
      
 63 
     | 
    
         
            +
                        "ACTIVE"    => "actv",
         
     | 
| 
      
 64 
     | 
    
         
            +
                        "STOPPED"   => "stop",
         
     | 
| 
      
 65 
     | 
    
         
            +
                        "SUSPENDED" => "susp",
         
     | 
| 
      
 66 
     | 
    
         
            +
                        "DONE"      => "done",
         
     | 
| 
      
 67 
     | 
    
         
            +
                        "FAILED"    => "fail",
         
     | 
| 
      
 68 
     | 
    
         
            +
                        "POWEROFF"  => "poff"
         
     | 
| 
      
 69 
     | 
    
         
            +
                    }
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                    SHORT_LCM_STATES={
         
     | 
| 
      
 72 
     | 
    
         
            +
                        "PROLOG"            => "prol",
         
     | 
| 
      
 73 
     | 
    
         
            +
                        "BOOT"              => "boot",
         
     | 
| 
      
 74 
     | 
    
         
            +
                        "RUNNING"           => "runn",
         
     | 
| 
      
 75 
     | 
    
         
            +
                        "MIGRATE"           => "migr",
         
     | 
| 
      
 76 
     | 
    
         
            +
                        "SAVE_STOP"         => "save",
         
     | 
| 
      
 77 
     | 
    
         
            +
                        "SAVE_SUSPEND"      => "save",
         
     | 
| 
      
 78 
     | 
    
         
            +
                        "SAVE_MIGRATE"      => "save",
         
     | 
| 
      
 79 
     | 
    
         
            +
                        "PROLOG_MIGRATE"    => "migr",
         
     | 
| 
      
 80 
     | 
    
         
            +
                        "PROLOG_RESUME"     => "prol",
         
     | 
| 
      
 81 
     | 
    
         
            +
                        "EPILOG_STOP"       => "epil",
         
     | 
| 
      
 82 
     | 
    
         
            +
                        "EPILOG"            => "epil",
         
     | 
| 
      
 83 
     | 
    
         
            +
                        "SHUTDOWN"          => "shut",
         
     | 
| 
      
 84 
     | 
    
         
            +
                        "CANCEL"            => "shut",
         
     | 
| 
      
 85 
     | 
    
         
            +
                        "FAILURE"           => "fail",
         
     | 
| 
      
 86 
     | 
    
         
            +
                        "CLEANUP_RESUBMIT"  => "clea",
         
     | 
| 
      
 87 
     | 
    
         
            +
                        "UNKNOWN"           => "unkn",
         
     | 
| 
      
 88 
     | 
    
         
            +
                        "HOTPLUG"           => "hotp",
         
     | 
| 
      
 89 
     | 
    
         
            +
                        "SHUTDOWN_POWEROFF" => "shut",
         
     | 
| 
      
 90 
     | 
    
         
            +
                        "BOOT_UNKNOWN"      => "boot",
         
     | 
| 
      
 91 
     | 
    
         
            +
                        "BOOT_POWEROFF"     => "boot",
         
     | 
| 
      
 92 
     | 
    
         
            +
                        "BOOT_SUSPENDED"    => "boot",
         
     | 
| 
      
 93 
     | 
    
         
            +
                        "BOOT_STOPPED"      => "boot",
         
     | 
| 
      
 94 
     | 
    
         
            +
                        "CLEANUP_DELETE"    => "clea",
         
     | 
| 
      
 95 
     | 
    
         
            +
                        "HOTPLUG_SNAPSHOT"  => "snap",
         
     | 
| 
      
 96 
     | 
    
         
            +
                        "HOTPLUG_NIC"       => "hotp",
         
     | 
| 
      
 97 
     | 
    
         
            +
                        "HOTPLUG_SAVEAS"           => "hotp",
         
     | 
| 
      
 98 
     | 
    
         
            +
                        "HOTPLUG_SAVEAS_POWEROFF"  => "hotp",
         
     | 
| 
      
 99 
     | 
    
         
            +
                        "HOTPLUG_SAVEAS_SUSPENDED" => "hotp"
         
     | 
| 
      
 100 
     | 
    
         
            +
                    }
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                    MIGRATE_REASON=%w{NONE ERROR STOP_RESUME USER CANCEL}
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                    SHORT_MIGRATE_REASON={
         
     | 
| 
      
 105 
     | 
    
         
            +
                        "NONE"          => "none",
         
     | 
| 
      
 106 
     | 
    
         
            +
                        "ERROR"         => "erro",
         
     | 
| 
      
 107 
     | 
    
         
            +
                        "STOP_RESUME"   => "stop",
         
     | 
| 
      
 108 
     | 
    
         
            +
                        "USER"          => "user",
         
     | 
| 
      
 109 
     | 
    
         
            +
                        "CANCEL"        => "canc"
         
     | 
| 
      
 110 
     | 
    
         
            +
                    }
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                    # Creates a VirtualMachine description with just its identifier
         
     | 
| 
      
 113 
     | 
    
         
            +
                    # this method should be used to create plain VirtualMachine objects.
         
     | 
| 
      
 114 
     | 
    
         
            +
                    # +id+ the id of the vm
         
     | 
| 
      
 115 
     | 
    
         
            +
                    #
         
     | 
| 
      
 116 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 117 
     | 
    
         
            +
                    #   vnet = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
         
     | 
| 
      
 118 
     | 
    
         
            +
                    #
         
     | 
| 
      
 119 
     | 
    
         
            +
                    def VirtualMachine.build_xml(pe_id=nil)
         
     | 
| 
      
 120 
     | 
    
         
            +
                        if pe_id
         
     | 
| 
      
 121 
     | 
    
         
            +
                            vm_xml = "<VM><ID>#{pe_id}</ID></VM>"
         
     | 
| 
      
 122 
     | 
    
         
            +
                        else
         
     | 
| 
      
 123 
     | 
    
         
            +
                            vm_xml = "<VM></VM>"
         
     | 
| 
      
 124 
     | 
    
         
            +
                        end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                        XMLElement.build_xml(vm_xml, 'VM')
         
     | 
| 
      
 127 
     | 
    
         
            +
                    end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                    def VirtualMachine.get_reason(reason)
         
     | 
| 
      
 130 
     | 
    
         
            +
                        reason=MIGRATE_REASON[reason.to_i]
         
     | 
| 
      
 131 
     | 
    
         
            +
                        reason_str=SHORT_MIGRATE_REASON[reason]
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                        reason_str
         
     | 
| 
      
 134 
     | 
    
         
            +
                    end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                    # Class constructor
         
     | 
| 
      
 137 
     | 
    
         
            +
                    def initialize(xml, client)
         
     | 
| 
      
 138 
     | 
    
         
            +
                        super(xml,client)
         
     | 
| 
      
 139 
     | 
    
         
            +
                    end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 142 
     | 
    
         
            +
                    # XML-RPC Methods for the Virtual Machine Object
         
     | 
| 
      
 143 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                    # Retrieves the information of the given VirtualMachine.
         
     | 
| 
      
 146 
     | 
    
         
            +
                    def info()
         
     | 
| 
      
 147 
     | 
    
         
            +
                        super(VM_METHODS[:info], 'VM')
         
     | 
| 
      
 148 
     | 
    
         
            +
                    end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                    alias_method :info!, :info
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    # Allocates a new VirtualMachine in OpenNebula
         
     | 
| 
      
 153 
     | 
    
         
            +
                    #
         
     | 
| 
      
 154 
     | 
    
         
            +
                    # @param description [String] A string containing the template of
         
     | 
| 
      
 155 
     | 
    
         
            +
                    #   the VirtualMachine.
         
     | 
| 
      
 156 
     | 
    
         
            +
                    # @param hold [true,false] false to create the VM in pending state,
         
     | 
| 
      
 157 
     | 
    
         
            +
                    #   true to create it on hold
         
     | 
| 
      
 158 
     | 
    
         
            +
                    #
         
     | 
| 
      
 159 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 160 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 161 
     | 
    
         
            +
                    def allocate(description, hold=false)
         
     | 
| 
      
 162 
     | 
    
         
            +
                        super(VM_METHODS[:allocate], description, hold)
         
     | 
| 
      
 163 
     | 
    
         
            +
                    end
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                    # Replaces the template contents
         
     | 
| 
      
 166 
     | 
    
         
            +
                    #
         
     | 
| 
      
 167 
     | 
    
         
            +
                    # @param new_template New template contents. If no argument is provided
         
     | 
| 
      
 168 
     | 
    
         
            +
                    #   the object will be updated using the @xml variable
         
     | 
| 
      
 169 
     | 
    
         
            +
                    def update(new_template=nil)
         
     | 
| 
      
 170 
     | 
    
         
            +
                        super(VM_METHODS[:update], new_template)
         
     | 
| 
      
 171 
     | 
    
         
            +
                    end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                    # Returns the <USER_TEMPLATE> element in text form
         
     | 
| 
      
 174 
     | 
    
         
            +
                    #
         
     | 
| 
      
 175 
     | 
    
         
            +
                    # @param indent [true,false] indents the resulting string, defaults to true
         
     | 
| 
      
 176 
     | 
    
         
            +
                    #
         
     | 
| 
      
 177 
     | 
    
         
            +
                    # @return [String] The USER_TEMPLATE
         
     | 
| 
      
 178 
     | 
    
         
            +
                    def user_template_str(indent=true)
         
     | 
| 
      
 179 
     | 
    
         
            +
                        template_like_str('USER_TEMPLATE', indent)
         
     | 
| 
      
 180 
     | 
    
         
            +
                    end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                    # Returns the <USER_TEMPLATE> element in XML form
         
     | 
| 
      
 183 
     | 
    
         
            +
                    #
         
     | 
| 
      
 184 
     | 
    
         
            +
                    # @return [String] The USER_TEMPLATE
         
     | 
| 
      
 185 
     | 
    
         
            +
                    def user_template_xml
         
     | 
| 
      
 186 
     | 
    
         
            +
                        if NOKOGIRI
         
     | 
| 
      
 187 
     | 
    
         
            +
                            @xml.xpath('TEMPLATE').to_s
         
     | 
| 
      
 188 
     | 
    
         
            +
                        else
         
     | 
| 
      
 189 
     | 
    
         
            +
                            @xml.elements['TEMPLATE'].to_s
         
     | 
| 
      
 190 
     | 
    
         
            +
                        end
         
     | 
| 
      
 191 
     | 
    
         
            +
                    end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
                    # Initiates the instance of the VM on the target host.
         
     | 
| 
      
 195 
     | 
    
         
            +
                    #
         
     | 
| 
      
 196 
     | 
    
         
            +
                    # @param host_id [Interger] The host id (hid) of the target host where
         
     | 
| 
      
 197 
     | 
    
         
            +
                    #   the VM will be instantiated.
         
     | 
| 
      
 198 
     | 
    
         
            +
                    # @param enforce [true|false] If it is set to true, the host capacity
         
     | 
| 
      
 199 
     | 
    
         
            +
                    #   will be checked, and the deployment will fail if the host is
         
     | 
| 
      
 200 
     | 
    
         
            +
                    #   overcommited. Defaults to false
         
     | 
| 
      
 201 
     | 
    
         
            +
                    #
         
     | 
| 
      
 202 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 203 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 204 
     | 
    
         
            +
                    def deploy(host_id, enforce=false)
         
     | 
| 
      
 205 
     | 
    
         
            +
                        return call(VM_METHODS[:deploy], @pe_id, host_id.to_i, enforce)
         
     | 
| 
      
 206 
     | 
    
         
            +
                    end
         
     | 
| 
      
 207 
     | 
    
         
            +
             
     | 
| 
      
 208 
     | 
    
         
            +
                    # Shutdowns an already deployed VM
         
     | 
| 
      
 209 
     | 
    
         
            +
                    def shutdown(hard=false)
         
     | 
| 
      
 210 
     | 
    
         
            +
                        action(hard ? 'shutdown-hard' : 'shutdown')
         
     | 
| 
      
 211 
     | 
    
         
            +
                    end
         
     | 
| 
      
 212 
     | 
    
         
            +
             
     | 
| 
      
 213 
     | 
    
         
            +
                    # Powers off a running VM
         
     | 
| 
      
 214 
     | 
    
         
            +
                    def poweroff
         
     | 
| 
      
 215 
     | 
    
         
            +
                        action('poweroff')
         
     | 
| 
      
 216 
     | 
    
         
            +
                    end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                    # Reboots an already deployed VM
         
     | 
| 
      
 219 
     | 
    
         
            +
                    def reboot(hard=false)
         
     | 
| 
      
 220 
     | 
    
         
            +
                        action(hard ? 'reboot-hard' : 'reboot')
         
     | 
| 
      
 221 
     | 
    
         
            +
                    end
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
      
 223 
     | 
    
         
            +
                    # @deprecated use {#reboot}
         
     | 
| 
      
 224 
     | 
    
         
            +
                    def reset
         
     | 
| 
      
 225 
     | 
    
         
            +
                        reboot(true)
         
     | 
| 
      
 226 
     | 
    
         
            +
                    end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
                    # @deprecated use {#shutdown}
         
     | 
| 
      
 229 
     | 
    
         
            +
                    def cancel
         
     | 
| 
      
 230 
     | 
    
         
            +
                        shutdown(true)
         
     | 
| 
      
 231 
     | 
    
         
            +
                    end
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
                    # Sets a VM to hold state, scheduler will not deploy it
         
     | 
| 
      
 234 
     | 
    
         
            +
                    def hold
         
     | 
| 
      
 235 
     | 
    
         
            +
                        action('hold')
         
     | 
| 
      
 236 
     | 
    
         
            +
                    end
         
     | 
| 
      
 237 
     | 
    
         
            +
             
     | 
| 
      
 238 
     | 
    
         
            +
                    # Releases a VM from hold state
         
     | 
| 
      
 239 
     | 
    
         
            +
                    def release
         
     | 
| 
      
 240 
     | 
    
         
            +
                        action('release')
         
     | 
| 
      
 241 
     | 
    
         
            +
                    end
         
     | 
| 
      
 242 
     | 
    
         
            +
             
     | 
| 
      
 243 
     | 
    
         
            +
                    # Stops a running VM
         
     | 
| 
      
 244 
     | 
    
         
            +
                    def stop
         
     | 
| 
      
 245 
     | 
    
         
            +
                        action('stop')
         
     | 
| 
      
 246 
     | 
    
         
            +
                    end
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
                    # Saves a running VM
         
     | 
| 
      
 249 
     | 
    
         
            +
                    def suspend
         
     | 
| 
      
 250 
     | 
    
         
            +
                        action('suspend')
         
     | 
| 
      
 251 
     | 
    
         
            +
                    end
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
                    # Resumes the execution of a saved VM
         
     | 
| 
      
 254 
     | 
    
         
            +
                    def resume
         
     | 
| 
      
 255 
     | 
    
         
            +
                        action('resume')
         
     | 
| 
      
 256 
     | 
    
         
            +
                    end
         
     | 
| 
      
 257 
     | 
    
         
            +
             
     | 
| 
      
 258 
     | 
    
         
            +
                    # Attaches a disk to a running VM
         
     | 
| 
      
 259 
     | 
    
         
            +
                    #
         
     | 
| 
      
 260 
     | 
    
         
            +
                    # @param disk_template [String] Template containing a DISK element
         
     | 
| 
      
 261 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 262 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 263 
     | 
    
         
            +
                    def disk_attach(disk_template)
         
     | 
| 
      
 264 
     | 
    
         
            +
                        return call(VM_METHODS[:attach], @pe_id, disk_template)
         
     | 
| 
      
 265 
     | 
    
         
            +
                    end
         
     | 
| 
      
 266 
     | 
    
         
            +
             
     | 
| 
      
 267 
     | 
    
         
            +
                    alias_method :attachdisk, :disk_attach
         
     | 
| 
      
 268 
     | 
    
         
            +
             
     | 
| 
      
 269 
     | 
    
         
            +
                    # Detaches a disk from a running VM
         
     | 
| 
      
 270 
     | 
    
         
            +
                    #
         
     | 
| 
      
 271 
     | 
    
         
            +
                    # @param disk_id [Integer] Id of the disk to be detached
         
     | 
| 
      
 272 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 273 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 274 
     | 
    
         
            +
                    def disk_detach(disk_id)
         
     | 
| 
      
 275 
     | 
    
         
            +
                        return call(VM_METHODS[:detach], @pe_id, disk_id)
         
     | 
| 
      
 276 
     | 
    
         
            +
                    end
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
                    alias_method :detachdisk, :disk_detach
         
     | 
| 
      
 279 
     | 
    
         
            +
             
     | 
| 
      
 280 
     | 
    
         
            +
                    # Attaches a NIC to a running VM
         
     | 
| 
      
 281 
     | 
    
         
            +
                    #
         
     | 
| 
      
 282 
     | 
    
         
            +
                    # @param nic_template [String] Template containing a NIC element
         
     | 
| 
      
 283 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 284 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 285 
     | 
    
         
            +
                    def nic_attach(nic_template)
         
     | 
| 
      
 286 
     | 
    
         
            +
                        return call(VM_METHODS[:attachnic], @pe_id, nic_template)
         
     | 
| 
      
 287 
     | 
    
         
            +
                    end
         
     | 
| 
      
 288 
     | 
    
         
            +
             
     | 
| 
      
 289 
     | 
    
         
            +
                    # Detaches a NIC from a running VM
         
     | 
| 
      
 290 
     | 
    
         
            +
                    #
         
     | 
| 
      
 291 
     | 
    
         
            +
                    # @param disk_id [Integer] Id of the NIC to be detached
         
     | 
| 
      
 292 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 293 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 294 
     | 
    
         
            +
                    def nic_detach(nic_id)
         
     | 
| 
      
 295 
     | 
    
         
            +
                        return call(VM_METHODS[:detachnic], @pe_id, nic_id)
         
     | 
| 
      
 296 
     | 
    
         
            +
                    end
         
     | 
| 
      
 297 
     | 
    
         
            +
             
     | 
| 
      
 298 
     | 
    
         
            +
                    # Deletes a VM from the pool
         
     | 
| 
      
 299 
     | 
    
         
            +
                    def destroy(recreate=false)
         
     | 
| 
      
 300 
     | 
    
         
            +
                        if recreate
         
     | 
| 
      
 301 
     | 
    
         
            +
                            action('destroy-recreate')
         
     | 
| 
      
 302 
     | 
    
         
            +
                        else
         
     | 
| 
      
 303 
     | 
    
         
            +
                            action('destroy')
         
     | 
| 
      
 304 
     | 
    
         
            +
                        end
         
     | 
| 
      
 305 
     | 
    
         
            +
                    end
         
     | 
| 
      
 306 
     | 
    
         
            +
             
     | 
| 
      
 307 
     | 
    
         
            +
                    # @deprecated use {#destroy} instead
         
     | 
| 
      
 308 
     | 
    
         
            +
                    def finalize(recreate=false)
         
     | 
| 
      
 309 
     | 
    
         
            +
                        destroy(recreate)
         
     | 
| 
      
 310 
     | 
    
         
            +
                    end
         
     | 
| 
      
 311 
     | 
    
         
            +
             
     | 
| 
      
 312 
     | 
    
         
            +
                    # Forces a re-deployment of a VM in UNKNOWN or BOOT state
         
     | 
| 
      
 313 
     | 
    
         
            +
                    def boot
         
     | 
| 
      
 314 
     | 
    
         
            +
                        action('boot')
         
     | 
| 
      
 315 
     | 
    
         
            +
                    end
         
     | 
| 
      
 316 
     | 
    
         
            +
             
     | 
| 
      
 317 
     | 
    
         
            +
                    alias_method :restart, :boot
         
     | 
| 
      
 318 
     | 
    
         
            +
             
     | 
| 
      
 319 
     | 
    
         
            +
                    # @deprecated use {#destroy} instead
         
     | 
| 
      
 320 
     | 
    
         
            +
                    def resubmit
         
     | 
| 
      
 321 
     | 
    
         
            +
                        action('destroy-recreate')
         
     | 
| 
      
 322 
     | 
    
         
            +
                    end
         
     | 
| 
      
 323 
     | 
    
         
            +
             
     | 
| 
      
 324 
     | 
    
         
            +
                    # Sets the re-scheduling flag for the VM
         
     | 
| 
      
 325 
     | 
    
         
            +
                    def resched
         
     | 
| 
      
 326 
     | 
    
         
            +
                        action('resched')
         
     | 
| 
      
 327 
     | 
    
         
            +
                    end
         
     | 
| 
      
 328 
     | 
    
         
            +
             
     | 
| 
      
 329 
     | 
    
         
            +
                    # Unsets the re-scheduling flag for the VM
         
     | 
| 
      
 330 
     | 
    
         
            +
                    def unresched
         
     | 
| 
      
 331 
     | 
    
         
            +
                        action('unresched')
         
     | 
| 
      
 332 
     | 
    
         
            +
                    end
         
     | 
| 
      
 333 
     | 
    
         
            +
             
     | 
| 
      
 334 
     | 
    
         
            +
                    # Moves a running VM to the specified host. With live=true the
         
     | 
| 
      
 335 
     | 
    
         
            +
                    # migration is done withdout downtime.
         
     | 
| 
      
 336 
     | 
    
         
            +
                    #
         
     | 
| 
      
 337 
     | 
    
         
            +
                    # @param host_id [Interger] The host id (hid) of the target host where
         
     | 
| 
      
 338 
     | 
    
         
            +
                    #   the VM will be migrated.
         
     | 
| 
      
 339 
     | 
    
         
            +
                    # @param live [true|false] If true the migration is done without
         
     | 
| 
      
 340 
     | 
    
         
            +
                    #   downtime. Defaults to false
         
     | 
| 
      
 341 
     | 
    
         
            +
                    # @param enforce [true|false] If it is set to true, the host capacity
         
     | 
| 
      
 342 
     | 
    
         
            +
                    #   will be checked, and the deployment will fail if the host is
         
     | 
| 
      
 343 
     | 
    
         
            +
                    #   overcommited. Defaults to false
         
     | 
| 
      
 344 
     | 
    
         
            +
                    #
         
     | 
| 
      
 345 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 346 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 347 
     | 
    
         
            +
                    def migrate(host_id, live=false, enforce=false)
         
     | 
| 
      
 348 
     | 
    
         
            +
                        call(VM_METHODS[:migrate], @pe_id, host_id.to_i, live==true,
         
     | 
| 
      
 349 
     | 
    
         
            +
                            enforce)
         
     | 
| 
      
 350 
     | 
    
         
            +
                    end
         
     | 
| 
      
 351 
     | 
    
         
            +
             
     | 
| 
      
 352 
     | 
    
         
            +
                    # @deprecated use {#migrate} instead
         
     | 
| 
      
 353 
     | 
    
         
            +
                    def live_migrate(host_id, enforce=false)
         
     | 
| 
      
 354 
     | 
    
         
            +
                        migrate(host_id, true, enforce)
         
     | 
| 
      
 355 
     | 
    
         
            +
                    end
         
     | 
| 
      
 356 
     | 
    
         
            +
             
     | 
| 
      
 357 
     | 
    
         
            +
                    # Set the specified vm's disk to be saved in a new image
         
     | 
| 
      
 358 
     | 
    
         
            +
                    # when the VirtualMachine shutdowns
         
     | 
| 
      
 359 
     | 
    
         
            +
                    #
         
     | 
| 
      
 360 
     | 
    
         
            +
                    # @param disk_id [Integer] ID of the disk to be saved
         
     | 
| 
      
 361 
     | 
    
         
            +
                    # @param image_name [String] Name for the new image where the
         
     | 
| 
      
 362 
     | 
    
         
            +
                    #   disk will be saved
         
     | 
| 
      
 363 
     | 
    
         
            +
                    # @param image_type [String] Type of the new image. Set to empty string
         
     | 
| 
      
 364 
     | 
    
         
            +
                    #   to use the default type
         
     | 
| 
      
 365 
     | 
    
         
            +
                    # @param hot [true|false] True to save the disk immediately, false will
         
     | 
| 
      
 366 
     | 
    
         
            +
                    #   perform the operation when the VM shuts down
         
     | 
| 
      
 367 
     | 
    
         
            +
                    #
         
     | 
| 
      
 368 
     | 
    
         
            +
                    # @return [Integer, OpenNebula::Error] the new Image ID in case of
         
     | 
| 
      
 369 
     | 
    
         
            +
                    #   success, error otherwise
         
     | 
| 
      
 370 
     | 
    
         
            +
                    def disk_snapshot(disk_id, image_name, image_type="", hot=false)
         
     | 
| 
      
 371 
     | 
    
         
            +
                        return Error.new('ID not defined') if !@pe_id
         
     | 
| 
      
 372 
     | 
    
         
            +
             
     | 
| 
      
 373 
     | 
    
         
            +
                        rc = @client.call(VM_METHODS[:savedisk],
         
     | 
| 
      
 374 
     | 
    
         
            +
                                          @pe_id,
         
     | 
| 
      
 375 
     | 
    
         
            +
                                          disk_id,
         
     | 
| 
      
 376 
     | 
    
         
            +
                                          image_name,
         
     | 
| 
      
 377 
     | 
    
         
            +
                                          image_type,
         
     | 
| 
      
 378 
     | 
    
         
            +
                                          hot)
         
     | 
| 
      
 379 
     | 
    
         
            +
             
     | 
| 
      
 380 
     | 
    
         
            +
                        return rc
         
     | 
| 
      
 381 
     | 
    
         
            +
                    end
         
     | 
| 
      
 382 
     | 
    
         
            +
             
     | 
| 
      
 383 
     | 
    
         
            +
                    # @deprecated use {#disk_snapshot}
         
     | 
| 
      
 384 
     | 
    
         
            +
                    def save_as(disk_id, image_name, image_type="", hot=false)
         
     | 
| 
      
 385 
     | 
    
         
            +
                        return disk_snapshot(disk_id, image_name, image_type, hot)
         
     | 
| 
      
 386 
     | 
    
         
            +
                    end
         
     | 
| 
      
 387 
     | 
    
         
            +
             
     | 
| 
      
 388 
     | 
    
         
            +
                    # Resize the VM
         
     | 
| 
      
 389 
     | 
    
         
            +
                    #
         
     | 
| 
      
 390 
     | 
    
         
            +
                    # @param capacity_template [String] Template containing the new capacity
         
     | 
| 
      
 391 
     | 
    
         
            +
                    #   elements CPU, VCPU, MEMORY. If one of them is not present, or its
         
     | 
| 
      
 392 
     | 
    
         
            +
                    #   value is 0, it will not be resized
         
     | 
| 
      
 393 
     | 
    
         
            +
                    # @param enforce [true|false] If it is set to true, the host capacity
         
     | 
| 
      
 394 
     | 
    
         
            +
                    #   will be checked. This will only affect oneadmin requests, regular users
         
     | 
| 
      
 395 
     | 
    
         
            +
                    #   resize requests will always be enforced
         
     | 
| 
      
 396 
     | 
    
         
            +
                    #
         
     | 
| 
      
 397 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 398 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 399 
     | 
    
         
            +
                    def resize(capacity_template, enforce)
         
     | 
| 
      
 400 
     | 
    
         
            +
                        return call(VM_METHODS[:resize], @pe_id, capacity_template, enforce)
         
     | 
| 
      
 401 
     | 
    
         
            +
                    end
         
     | 
| 
      
 402 
     | 
    
         
            +
             
     | 
| 
      
 403 
     | 
    
         
            +
                    # Changes the owner/group
         
     | 
| 
      
 404 
     | 
    
         
            +
                    # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
         
     | 
| 
      
 405 
     | 
    
         
            +
                    # gid:: _Integer_ the new group id. Set to -1 to leave the current one
         
     | 
| 
      
 406 
     | 
    
         
            +
                    # [return] nil in case of success or an Error object
         
     | 
| 
      
 407 
     | 
    
         
            +
                    def chown(uid, gid)
         
     | 
| 
      
 408 
     | 
    
         
            +
                        super(VM_METHODS[:chown], uid, gid)
         
     | 
| 
      
 409 
     | 
    
         
            +
                    end
         
     | 
| 
      
 410 
     | 
    
         
            +
             
     | 
| 
      
 411 
     | 
    
         
            +
                    # Changes the permissions.
         
     | 
| 
      
 412 
     | 
    
         
            +
                    #
         
     | 
| 
      
 413 
     | 
    
         
            +
                    # @param octet [String] Permissions octed , e.g. 640
         
     | 
| 
      
 414 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 415 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 416 
     | 
    
         
            +
                    def chmod_octet(octet)
         
     | 
| 
      
 417 
     | 
    
         
            +
                        super(VM_METHODS[:chmod], octet)
         
     | 
| 
      
 418 
     | 
    
         
            +
                    end
         
     | 
| 
      
 419 
     | 
    
         
            +
             
     | 
| 
      
 420 
     | 
    
         
            +
                    # Changes the permissions.
         
     | 
| 
      
 421 
     | 
    
         
            +
                    # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
         
     | 
| 
      
 422 
     | 
    
         
            +
                    #
         
     | 
| 
      
 423 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 424 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 425 
     | 
    
         
            +
                    def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
         
     | 
| 
      
 426 
     | 
    
         
            +
                            other_m, other_a)
         
     | 
| 
      
 427 
     | 
    
         
            +
                        super(VM_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
         
     | 
| 
      
 428 
     | 
    
         
            +
                            group_m, group_a, other_u, other_m, other_a)
         
     | 
| 
      
 429 
     | 
    
         
            +
                    end
         
     | 
| 
      
 430 
     | 
    
         
            +
             
     | 
| 
      
 431 
     | 
    
         
            +
                    # Retrieves this VM's monitoring data from OpenNebula
         
     | 
| 
      
 432 
     | 
    
         
            +
                    #
         
     | 
| 
      
 433 
     | 
    
         
            +
                    # @param [Array<String>] xpath_expressions Elements to retrieve.
         
     | 
| 
      
 434 
     | 
    
         
            +
                    #
         
     | 
| 
      
 435 
     | 
    
         
            +
                    # @return [Hash<String, Array<Array<int>>>, OpenNebula::Error] Hash with
         
     | 
| 
      
 436 
     | 
    
         
            +
                    #   the requested xpath expressions, and an Array of 'timestamp, value'.
         
     | 
| 
      
 437 
     | 
    
         
            +
                    #
         
     | 
| 
      
 438 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 439 
     | 
    
         
            +
                    #   vm.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )
         
     | 
| 
      
 440 
     | 
    
         
            +
                    #
         
     | 
| 
      
 441 
     | 
    
         
            +
                    #   { "NET_TX" =>
         
     | 
| 
      
 442 
     | 
    
         
            +
                    #       [["1337264510", "210"],
         
     | 
| 
      
 443 
     | 
    
         
            +
                    #        ["1337264553", "220"],
         
     | 
| 
      
 444 
     | 
    
         
            +
                    #        ["1337264584", "230"]],
         
     | 
| 
      
 445 
     | 
    
         
            +
                    #     "TEMPLATE/CUSTOM_PROBE" =>
         
     | 
| 
      
 446 
     | 
    
         
            +
                    #       [],
         
     | 
| 
      
 447 
     | 
    
         
            +
                    #     "CPU" =>
         
     | 
| 
      
 448 
     | 
    
         
            +
                    #       [["1337264510", "0"],
         
     | 
| 
      
 449 
     | 
    
         
            +
                    #        ["1337264553", "0"],
         
     | 
| 
      
 450 
     | 
    
         
            +
                    #        ["1337264584", "0"]]
         
     | 
| 
      
 451 
     | 
    
         
            +
                    #   }
         
     | 
| 
      
 452 
     | 
    
         
            +
                    def monitoring(xpath_expressions)
         
     | 
| 
      
 453 
     | 
    
         
            +
                        return super(VM_METHODS[:monitoring], 'VM',
         
     | 
| 
      
 454 
     | 
    
         
            +
                            'LAST_POLL', xpath_expressions)
         
     | 
| 
      
 455 
     | 
    
         
            +
                    end
         
     | 
| 
      
 456 
     | 
    
         
            +
             
     | 
| 
      
 457 
     | 
    
         
            +
                    # Retrieves this VM's monitoring data from OpenNebula, in XML
         
     | 
| 
      
 458 
     | 
    
         
            +
                    #
         
     | 
| 
      
 459 
     | 
    
         
            +
                    # @return [String] VM monitoring data, in XML
         
     | 
| 
      
 460 
     | 
    
         
            +
                    def monitoring_xml()
         
     | 
| 
      
 461 
     | 
    
         
            +
                        return Error.new('ID not defined') if !@pe_id
         
     | 
| 
      
 462 
     | 
    
         
            +
             
     | 
| 
      
 463 
     | 
    
         
            +
                        return @client.call(VM_METHODS[:monitoring], @pe_id)
         
     | 
| 
      
 464 
     | 
    
         
            +
                    end
         
     | 
| 
      
 465 
     | 
    
         
            +
             
     | 
| 
      
 466 
     | 
    
         
            +
                    # Renames this VM
         
     | 
| 
      
 467 
     | 
    
         
            +
                    #
         
     | 
| 
      
 468 
     | 
    
         
            +
                    # @param name [String] New name for the VM.
         
     | 
| 
      
 469 
     | 
    
         
            +
                    #
         
     | 
| 
      
 470 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 471 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 472 
     | 
    
         
            +
                    def rename(name)
         
     | 
| 
      
 473 
     | 
    
         
            +
                        return call(VM_METHODS[:rename], @pe_id, name)
         
     | 
| 
      
 474 
     | 
    
         
            +
                    end
         
     | 
| 
      
 475 
     | 
    
         
            +
             
     | 
| 
      
 476 
     | 
    
         
            +
                    # Creates a new VM snapshot
         
     | 
| 
      
 477 
     | 
    
         
            +
                    #
         
     | 
| 
      
 478 
     | 
    
         
            +
                    # @param name [String] Name for the snapshot.
         
     | 
| 
      
 479 
     | 
    
         
            +
                    #
         
     | 
| 
      
 480 
     | 
    
         
            +
                    # @return [Integer, OpenNebula::Error] The new snaphost ID in case
         
     | 
| 
      
 481 
     | 
    
         
            +
                    #   of success, Error otherwise
         
     | 
| 
      
 482 
     | 
    
         
            +
                    def snapshot_create(name="")
         
     | 
| 
      
 483 
     | 
    
         
            +
                        return Error.new('ID not defined') if !@pe_id
         
     | 
| 
      
 484 
     | 
    
         
            +
             
     | 
| 
      
 485 
     | 
    
         
            +
                        name ||= ""
         
     | 
| 
      
 486 
     | 
    
         
            +
                        return @client.call(VM_METHODS[:snapshotcreate], @pe_id, name)
         
     | 
| 
      
 487 
     | 
    
         
            +
                    end
         
     | 
| 
      
 488 
     | 
    
         
            +
             
     | 
| 
      
 489 
     | 
    
         
            +
                    # Reverts to a snapshot
         
     | 
| 
      
 490 
     | 
    
         
            +
                    #
         
     | 
| 
      
 491 
     | 
    
         
            +
                    # @param snap_id [Integer] Id of the snapshot
         
     | 
| 
      
 492 
     | 
    
         
            +
                    #
         
     | 
| 
      
 493 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 494 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 495 
     | 
    
         
            +
                    def snapshot_revert(snap_id)
         
     | 
| 
      
 496 
     | 
    
         
            +
                        return call(VM_METHODS[:snapshotrevert], @pe_id, snap_id)
         
     | 
| 
      
 497 
     | 
    
         
            +
                    end
         
     | 
| 
      
 498 
     | 
    
         
            +
             
     | 
| 
      
 499 
     | 
    
         
            +
                    # Deletes a  VM snapshot
         
     | 
| 
      
 500 
     | 
    
         
            +
                    #
         
     | 
| 
      
 501 
     | 
    
         
            +
                    # @param snap_id [Integer] Id of the snapshot
         
     | 
| 
      
 502 
     | 
    
         
            +
                    #
         
     | 
| 
      
 503 
     | 
    
         
            +
                    # @return [nil, OpenNebula::Error] nil in case of success, Error
         
     | 
| 
      
 504 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 505 
     | 
    
         
            +
                    def snapshot_delete(snap_id)
         
     | 
| 
      
 506 
     | 
    
         
            +
                        return call(VM_METHODS[:snapshotdelete], @pe_id, snap_id)
         
     | 
| 
      
 507 
     | 
    
         
            +
                    end
         
     | 
| 
      
 508 
     | 
    
         
            +
             
     | 
| 
      
 509 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 510 
     | 
    
         
            +
                    # Helpers to get VirtualMachine information
         
     | 
| 
      
 511 
     | 
    
         
            +
                    #######################################################################
         
     | 
| 
      
 512 
     | 
    
         
            +
             
     | 
| 
      
 513 
     | 
    
         
            +
                    # Returns the VM state of the VirtualMachine (numeric value)
         
     | 
| 
      
 514 
     | 
    
         
            +
                    def state
         
     | 
| 
      
 515 
     | 
    
         
            +
                        self['STATE'].to_i
         
     | 
| 
      
 516 
     | 
    
         
            +
                    end
         
     | 
| 
      
 517 
     | 
    
         
            +
             
     | 
| 
      
 518 
     | 
    
         
            +
                    # Returns the VM state of the VirtualMachine (string value)
         
     | 
| 
      
 519 
     | 
    
         
            +
                    def state_str
         
     | 
| 
      
 520 
     | 
    
         
            +
                        VM_STATE[state]
         
     | 
| 
      
 521 
     | 
    
         
            +
                    end
         
     | 
| 
      
 522 
     | 
    
         
            +
             
     | 
| 
      
 523 
     | 
    
         
            +
                    # Returns the LCM state of the VirtualMachine (numeric value)
         
     | 
| 
      
 524 
     | 
    
         
            +
                    def lcm_state
         
     | 
| 
      
 525 
     | 
    
         
            +
                        self['LCM_STATE'].to_i
         
     | 
| 
      
 526 
     | 
    
         
            +
                    end
         
     | 
| 
      
 527 
     | 
    
         
            +
             
     | 
| 
      
 528 
     | 
    
         
            +
                    # Returns the LCM state of the VirtualMachine (string value)
         
     | 
| 
      
 529 
     | 
    
         
            +
                    def lcm_state_str
         
     | 
| 
      
 530 
     | 
    
         
            +
                        LCM_STATE[lcm_state]
         
     | 
| 
      
 531 
     | 
    
         
            +
                    end
         
     | 
| 
      
 532 
     | 
    
         
            +
             
     | 
| 
      
 533 
     | 
    
         
            +
                    # Returns the short status string for the VirtualMachine
         
     | 
| 
      
 534 
     | 
    
         
            +
                    def status
         
     | 
| 
      
 535 
     | 
    
         
            +
                        short_state_str=SHORT_VM_STATES[state_str]
         
     | 
| 
      
 536 
     | 
    
         
            +
             
     | 
| 
      
 537 
     | 
    
         
            +
                        if short_state_str=="actv"
         
     | 
| 
      
 538 
     | 
    
         
            +
                            short_state_str=SHORT_LCM_STATES[lcm_state_str]
         
     | 
| 
      
 539 
     | 
    
         
            +
                        end
         
     | 
| 
      
 540 
     | 
    
         
            +
             
     | 
| 
      
 541 
     | 
    
         
            +
                        short_state_str
         
     | 
| 
      
 542 
     | 
    
         
            +
                    end
         
     | 
| 
      
 543 
     | 
    
         
            +
             
     | 
| 
      
 544 
     | 
    
         
            +
                    # Returns the group identifier
         
     | 
| 
      
 545 
     | 
    
         
            +
                    # [return] _Integer_ the element's group ID
         
     | 
| 
      
 546 
     | 
    
         
            +
                    def gid
         
     | 
| 
      
 547 
     | 
    
         
            +
                        self['GID'].to_i
         
     | 
| 
      
 548 
     | 
    
         
            +
                    end
         
     | 
| 
      
 549 
     | 
    
         
            +
             
     | 
| 
      
 550 
     | 
    
         
            +
                private
         
     | 
| 
      
 551 
     | 
    
         
            +
                    def action(name)
         
     | 
| 
      
 552 
     | 
    
         
            +
                        return Error.new('ID not defined') if !@pe_id
         
     | 
| 
      
 553 
     | 
    
         
            +
             
     | 
| 
      
 554 
     | 
    
         
            +
                        rc = @client.call(VM_METHODS[:action], name, @pe_id)
         
     | 
| 
      
 555 
     | 
    
         
            +
                        rc = nil if !OpenNebula.is_error?(rc)
         
     | 
| 
      
 556 
     | 
    
         
            +
             
     | 
| 
      
 557 
     | 
    
         
            +
                        return rc
         
     | 
| 
      
 558 
     | 
    
         
            +
                    end
         
     | 
| 
      
 559 
     | 
    
         
            +
                end
         
     | 
| 
      
 560 
     | 
    
         
            +
            end
         
     |