Module: OpenNebula

Defined in:
lib/opennebula/utils.rb,
lib/opennebula.rb,
lib/opennebula/acl.rb,
lib/opennebula/vdc.rb,
lib/opennebula/host.rb,
lib/opennebula/pool.rb,
lib/opennebula/user.rb,
lib/opennebula/zone.rb,
lib/opennebula/error.rb,
lib/opennebula/group.rb,
lib/opennebula/image.rb,
lib/opennebula/client.rb,
lib/opennebula/system.rb,
lib/opennebula/cluster.rb,
lib/opennebula/acl_pool.rb,
lib/opennebula/document.rb,
lib/opennebula/ssh_auth.rb,
lib/opennebula/template.rb,
lib/opennebula/vdc_pool.rb,
lib/opennebula/vm_group.rb,
lib/opennebula/xml_pool.rb,
lib/opennebula/datastore.rb,
lib/opennebula/host_pool.rb,
lib/opennebula/ldap_auth.rb,
lib/opennebula/user_pool.rb,
lib/opennebula/x509_auth.rb,
lib/opennebula/xml_utils.rb,
lib/opennebula/zone_pool.rb,
lib/opennebula/group_pool.rb,
lib/opennebula/image_pool.rb,
lib/opennebula/marketplace.rb,
lib/opennebula/xml_element.rb,
lib/opennebula/cluster_pool.rb,
lib/opennebula/pool_element.rb,
lib/opennebula/document_json.rb,
lib/opennebula/document_pool.rb,
lib/opennebula/template_pool.rb,
lib/opennebula/vm_group_pool.rb,
lib/opennebula/datastore_pool.rb,
lib/opennebula/marketplaceapp.rb,
lib/opennebula/security_group.rb,
lib/opennebula/virtual_router.rb,
lib/opennebula/virtual_machine.rb,
lib/opennebula/virtual_network.rb,
lib/opennebula/marketplace_pool.rb,
lib/opennebula/server_x509_auth.rb,
lib/opennebula/document_pool_json.rb,
lib/opennebula/server_cipher_auth.rb,
lib/opennebula/marketplaceapp_pool.rb,
lib/opennebula/security_group_pool.rb,
lib/opennebula/virtual_router_pool.rb,
lib/opennebula/virtual_machine_pool.rb,
lib/opennebula/virtual_network_pool.rb

Overview

————————————————————————– # Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #

#

Licensed under the Apache License, Version 2.0 (the “License”); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at #

#

www.apache.org/licenses/LICENSE-2.0 #

#

Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an “AS IS” BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ————————————————————————— #

Defined Under Namespace

Modules: ParsePoolBase Classes: Acl, AclPool, Client, Cluster, ClusterPool, Datastore, DatastorePool, Document, DocumentJSON, DocumentPool, DocumentPoolJSON, Error, Group, GroupPool, Host, HostPool, Image, ImagePool, LdapAuth, MarketPlace, MarketPlaceApp, MarketPlaceAppPool, MarketPlacePool, NokogiriStreamParser, OxStreamParser, ParsePoolSax, ParsePoolSaxBase, Pool, PoolElement, SecurityGroup, SecurityGroupPool, ServerCipherAuth, ServerX509Auth, SshAuth, System, Template, TemplatePool, User, UserPool, VMGroup, VMGroupPool, Vdc, VdcPool, VirtualMachine, VirtualMachinePool, VirtualNetwork, VirtualNetworkPool, VirtualRouter, VirtualRouterPool, X509Auth, XMLElement, XMLPool, Zone, ZonePool

Constant Summary collapse

VERSION =

OpenNebula version

'5.6.2'
DEFAULT_POOL_PAGE_SIZE =
200
@@pool_page_size =
DEFAULT_POOL_PAGE_SIZE

Class Method Summary collapse

Class Method Details

.decrypt(res, token) ⇒ Object

receive hashed values (res) with a token returns original values



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/opennebula/utils.rb', line 37

def self.decrypt(res, token)
    opts = {}

    res.each do |key, encrypted_value|
        decipher = OpenSSL::Cipher::AES.new(256,:CBC)
        decipher.decrypt
        decipher.key = token[0..31]
        plain = decipher.update(Base64::decode64(encrypted_value)) + decipher.final
        opts[key] = plain
    end
    return opts
end

.encrypt(opts, token) ⇒ Object

receive a object key => value format returns hashed values



24
25
26
27
28
29
30
31
32
33
# File 'lib/opennebula/utils.rb', line 24

def self.encrypt(opts, token)
    res = {}
    opts.each do |key, value|
        cipher = OpenSSL::Cipher::AES.new(256,:CBC)
        cipher.encrypt.key = token[0..31]
        encrypted = cipher.update(value) + cipher.final
        res[key] = Base64::encode64(encrypted).gsub("\n", "")
    end
    return res
end

.handle_driver_exception(action, ex, host, did = nil, id = nil, file = nil) ⇒ Object

>> /var/log/one/oned.log



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/opennebula/utils.rb', line 51

def self.handle_driver_exception(action, ex, host, did = nil, id = nil, file = nil)

    file    ||= ""
    id      ||= ""
    did     ||= ""
    OpenNebula::log_error(action + " of VM #{id} #{did} on host #{host} #{file} "+
                "due to \"#{ex.message}\"" +
                "\n********* STACK TRACE *********\n" +
                "\t#{ex.backtrace.join("\n\t")}" +
                "\n*******************************\n")

    OpenNebula.error_message("There is a problem: #{ex.message}")
    exit (-1)
end

.is_error?(value) ⇒ Boolean

Returns true if the object returned by a method of the OpenNebula library is an Error

Returns:

  • (Boolean)


56
57
58
# File 'lib/opennebula/error.rb', line 56

def self.is_error?(value)
    value.class==OpenNebula::Error
end

.pool_page_sizeObject



24
25
26
# File 'lib/opennebula/client.rb', line 24

def self.pool_page_size
    @@pool_page_size
end

.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions) ⇒ Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with the requested xpath expressions, and an Array of [timestamp, value].

Processes the monitoring data in XML returned by OpenNebula

Parameters:

  • xmldoc (XMLElement)

    monitoring data returned by OpenNebula

  • root_elem (String)

    Root for each individual PoolElement

  • timestamp_elem (String)

    Name of the XML element with the last monitorization timestamp

  • oid (Integer)

    Id of the object to process

  • xpath_expressions (Array<String>)

    Elements to retrieve.

Returns:

  • (Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with the requested xpath expressions, and an Array of [timestamp, value].)

    Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with the requested xpath expressions, and an Array of [timestamp, value].



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/opennebula/pool_element.rb', line 272

def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions)
    hash = {}
    timestamps = xmldoc.retrieve_elements(
        "#{root_elem}[ID=#{oid}]/#{timestamp_elem}")

    xpath_expressions.each { |xpath|
        xpath_values = xmldoc.retrieve_elements("#{root_elem}[ID=#{oid}]/#{xpath}")

        if ( xpath_values.nil? )
            hash[xpath] = []
        else
            hash[xpath] = timestamps.zip(xpath_values)
        end
    }

    return hash
end