Top Level Namespace

Includes:
IONeLoggerKit, ONeHelper, OpenNebula

Defined Under Namespace

Modules: Deferable, IONeLoggerKit, ONeHelper Classes: AnsiblePlaybook, AnsiblePlaybookProcess, Array, BasicObject, Hash, IONe, IPAddr, NilClass

Constant Summary collapse

STARTUP_TIME =

IONe server start time

Time.now().to_i
ROOT =

IONe root path

ENV['IONEROOT']
LOG_ROOT =

IONe logs path

LOG_LOCATION
MAIN_IONE =

Shows if current IONe Sunstone process was started by systemd(first time so). True or False

Process.ppid == 1
CONF =

for sure

$ione_conf
VERSION =

IONe version

File.read("#{ROOT}/meta/version.txt")
USERS_GROUP =

OpenNebula users group

$ione_conf['OpenNebula']['users-group']
TRIAL_SUSPEND_DELAY =

Trial VMs suspend delay

$ione_conf['Server']['trial-suspend-delay']
USERS_VMS_SSH_PORT =

Default SSH port at OpenNebula Virtual Machines

$ione_conf['OpenNebula']['users-vms-ssh-port']
CREDENTIALS =

OpenNebula credentials

File.read(VAR_LOCATION + "/.one/one_auth").chomp
ENDPOINT =

XML_RPC endpoint where OpenNebula is listening

$ione_conf['OpenNebula']['endpoint']
RPC_LOGGER =

Logger instance for rpc calls

Logger.new(rpc_log_file)
IONeAPIServerThread =

Public API bindings

Thread.new do
    require 'pry-remote'
    class IONeAPIServer < Sinatra::Base
        set :bind, '0.0.0.0'
        set :port, 8009

        before do
            @request_body = request.body.read
        end

        get '/' do
            'Hello, World! via IONe Web API'
        end
        post '/ione/:method' do | method |
            begin
                args = JSON.parse(@request_body)
                u = User.new_with_id(-1, Client.new(args['auth']))
                rc = u.info!
                if OpenNebula.is_error?(rc)
                    raise "False Credentials given"
                end
                RPC_LOGGER.debug "IONeAPI calls proxy method #{method}(#{args['params'].collect {|p| p.inspect}.join(", ")})"
                r = IONe.new(Client.new(params['auth']), $db).send(method, *args['params'])
            rescue => e
                r = e.message
                backtrace = e.backtrace
            end
            RPC_LOGGER.debug "IONeAPI sends response #{r.inspect}"
            RPC_LOGGER.debug "Backtrace #{backtrace.inspect}" if defined? backtrace
            JSON.pretty_generate response: r
        end
        get %r{one\.(\w+)\.(\w+)} do
            JSON.pretty_generate params[:captures]
        end
    end

    RPC_LOGGER.debug "Starting up IONeAPI Server on port 8009"
    begin
        run IONeAPIServer.run!
    rescue StandardError => e
        RPC_LOGGER.debug e.message
    end
end
ANSIBLE_HOST =

Hostname or IP-address of host where ansible installed

$ione_conf['AnsibleServer']['host']
ANSIBLE_HOST_PORT =

Ansible-host SSH-port

$ione_conf['AnsibleServer']['port']
ANSIBLE_HOST_USER =

SSH user to user

$ione_conf['AnsibleServer']['user']

Constants included from ONeHelper

ONeHelper::ON_INSTANCES, ONeHelper::VIM

Constants included from IONeLoggerKit

IONeLoggerKit::DESTINATIONS

Instance Method Summary collapse

Methods included from ONeHelper

#ChooseDS, #ClusterType, #get_ds_vdata, #get_pool_element, #get_vcenter_dc, #onblock, #putc, #recursive_find_ds, #recursive_find_vm

Methods included from IONeLoggerKit

#LOG, #LOG_AUTO, #LOG_CALL, #LOG_COLOR, #LOG_DEBUG, #id_gen

Instance Method Details

#check_total(r) ⇒ Object

Simple test for an #IaaS_Gate method



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/accounting/tests.rb', line 2

def check_total r
    r.each do |key, value|
        next if key == 'TOTAL' || key == 'time_period_requested'
        showback = value['showback']

        if showback.nil? && value.class != Hash then
            print key.to_s.red, ' -- ', value, "\n"
            next
        elsif value.class == Hash && value['EXCEPTION'] == 'No Records' then
            puts "----------------------------#{key.to_s}----------------------------".yellow
            next
        end

        puts "----------------------------#{key.to_s}----------------------------"

        showback.each do | record |
            string = record['CPU'].to_s + ' + '
            string += record['MEMORY'].to_s + ' + '
            string += record['DISK'].to_s + ' + '
            string += record['PUBLIC_IP'].to_s

            string += ' -> ' + (record['CPU'] + record['MEMORY'] + record['DISK'] + record['PUBLIC_IP']).to_s
            string += ' == ' + record['TOTAL'].to_s
            string += ' | ' + record['date']

            if record['CPU'] + record['MEMORY'] + record['DISK'] + record['PUBLIC_IP'] != record['TOTAL'] then
                string = string.red
            else
                string = string.green
            end
            puts string
        end
    end
end

#class_from_string(str) ⇒ Object

Generates class from string class-name



4
5
6
7
8
# File 'lib/ione-scheduler/main.rb', line 4

def class_from_string(str)
    str.split('::').inject(Object) do |mod, class_name|
      mod.const_get(class_name)
    end
end

#fmt_time(sec) ⇒ String

Formats time from seconds from the start of Time to dd:hh:mm:ss format

Parameters:

  • sec (Integer)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
# File 'service/time.rb', line 10

def fmt_time(sec)
    sec = sec.to_i
    days = (sec / 86400).to_i
    sec -= days * 86400
    hours = (sec / 3600.0).to_i
    sec -= hours * 3600
    minutes = (sec / 60.0).to_i
    "#{days}d:#{hours}h:#{minutes}m:#{sec % 60}s"
end

#Invoke(action) ⇒ Object

Invokes scheduled action



34
35
36
37
# File 'lib/ione-scheduler/main.rb', line 34

def Invoke(action)
    Unschedule(action['id'])
    IONe.new($client, $db).send(action['method'], *(JSON.parse(action['params'])))
end

#LOG_STAT(method = caller_locations(1,1)[0].label, time = Time.now.to_i) ⇒ Object

Logging calls to stat-data and sys.log



16
17
18
19
20
21
22
23
24
25
# File 'modules/stat/main.rb', line 16

def LOG_STAT(method = caller_locations(1,1)[0].label, time = Time.now.to_i)
    $data[method] = {} if $data[method].nil?
    $data[method]['calls'] = [] if $data[method]['calls'].nil?
    $data[method]['counter'] = 0 if $data[method]['counter'].nil?
    $data[method]['counter'] += 1
    $data[method]['calls'] << time
    `echo > #{ROOT}/modules/stat/data.json`
    File.open("#{ROOT}/modules/stat/data.json", 'w') { |file| file.write(JSON.pretty_generate($data)) }    
    nil
end

#NewQuota(login, vmquota, cpu, memory, disk) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates quota template



3
4
5
6
7
8
9
10
# File 'service/quotagen.rb', line 3

def NewQuota(, vmquota, cpu, memory, disk)
    quota = "VM=[
            CPU=\"#{cpu}\",
            MEMORY=\"#{memory}\",
            SYSTEM_DISK_SIZE=\"#{disk}\",
            VMS=\"#{vmquota}\" ]"
    quota
end

#Schedule(time, action, *params) ⇒ Object

Schedules action



16
17
18
19
20
21
22
23
24
# File 'lib/ione-scheduler/main.rb', line 16

def Schedule(time, action, *params)
    # action = action.split('.')

    @db_client.query(
        "INSERT INTO action (method, params, time)
         VALUES ('#{action}', '#{JSON.generate(params)}', '#{time}')"
    )
    @db_client.query('SELECT * FROM action').to_a.last['id']
end

#timeString

Returns current time in ctime format

Returns:

  • (String)


3
4
5
# File 'service/time.rb', line 3

def time
    Time.now.ctime
end

#Unschedule(id) ⇒ Object

Unschedules action



27
28
29
30
31
# File 'lib/ione-scheduler/main.rb', line 27

def Unschedule(id)
    @db_client.query(
        "DELETE FROM action WHERE id=#{id}"
    )
end