Class: Fog::Compute::OpenNebula::Mock

Inherits:
Object
  • Object
show all
Includes:
Collections
Defined in:
lib/fog/opennebula/requests/compute/template_pool.rb,
lib/fog/opennebula/compute.rb,
lib/fog/opennebula/requests/compute/list_vms.rb,
lib/fog/opennebula/requests/compute/vm_destroy.rb,
lib/fog/opennebula/requests/compute/list_groups.rb,
lib/fog/opennebula/requests/compute/vm_allocate.rb,
lib/fog/opennebula/requests/compute/list_networks.rb,
lib/fog/opennebula/requests/compute/get_vnc_console.rb

Overview

class Real

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



34
35
36
# File 'lib/fog/opennebula/compute.rb', line 34

def initialize(options={})
  require 'opennebula'
end

Instance Method Details

#clientObject



38
39
40
# File 'lib/fog/opennebula/compute.rb', line 38

def client
  return @client
end

#get_vnc_console(server_id, console_type) ⇒ Object

Get a vnc console for an instance.

Parameters

  • server_id <~String> - The ID of the server.

  • console_type <~String> - Type of vnc console to get (‘novnc’ or ‘xvpvnc’).

Returns

  • response <~Excon::Response>:

    • body <~Hash>:

      • url <~String>

      • type <~String>



16
17
18
19
20
21
22
23
24
# File 'lib/fog/opennebula/requests/compute/get_vnc_console.rb', line 16

def get_vnc_console(server_id, console_type)
  body = {
      :type => "novnc",
      :proxy_port => "29876",
      :password => "null",
      :token => "3n32dtwpsdj5jkug3b4w",
      :proxy_host => "example.com"
  }
end

#list_groups(filter = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fog/opennebula/requests/compute/list_groups.rb', line 43

def list_groups(filter={})
  groups = []
  net1 = mock_group "1", 'net1'
  net2 = mock_group "2", 'fogtest'

  grouppool = [net1, net2]
  grouppool.each do |group| 
    filter_missmatch = false

    unless (filter.empty?)
      filter.each do |k,v|
        if group["#{k.to_s.upcase}"] && group["#{k.to_s.upcase}"] != v.to_s
          filter_missmatch = true
          break
        end
      end 
      next if filter_missmatch
    end 
    groups << {:id => group["ID"], :name => group["NAME"]}
  end
  groups
end

#list_networks(filters = {}) ⇒ Object



44
45
46
47
48
# File 'lib/fog/opennebula/requests/compute/list_networks.rb', line 44

def list_networks(filters={})
  net1 = mock_network 'net1'
  net2 = mock_network 'net2'
  [net1, net2]
end

#list_vms(filter = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/opennebula/requests/compute/list_vms.rb', line 55

def list_vms(filter = {})
  if filter[:id].nil?
    vm1 = mock_vm 'fog-vm1'
    vm2 = mock_vm 'fog-vm2'
    vm3 = mock_vm 'fog-vm3'
    return [vm1, vm2, vm3]
  elsif filter[:mock_return]
    mock_vm 'fog-vm1', filter[:id]
  else 
    []
  end
end

#mock_group(id, name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/opennebula/requests/compute/list_groups.rb', line 66

def mock_group id, name
  {
    "ID"    	 => id,
    "NAME"  	 => name,
    "UID"   	 => "5",
    "GID"   	 => "5",
    "DESCRIPTION" => "netDescription",
    "VLAN"	 => "5"
  }
end

#mock_network(name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/opennebula/requests/compute/list_networks.rb', line 50

def mock_network name
  {
    :id    	 => "5",
    :name  	 => name,
	    :uid   	 => "5",
	    :gid   	 => "5",
	    :description => "netDescription",
	    :vlan	 => "5"
  }
end

#mock_vm(name, id = 4) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/opennebula/requests/compute/list_vms.rb', line 67

def mock_vm(name, id=4)
  data = {}
  data["onevm_object"] = ""
  data["status"] = "Running"
  data["state"]  = "3"
  data["id"]     = id
  data["uuid"]   = "5"
  data["gid"]    = "5"
  data["name"]   = "MockVM-#{name}"
  data["user"]   = "MockUser" 
  data["group"]  = "MockGroup"
  data["cpu"]    = "2"
  data["memory"] = "1024"
  data["mac"]	 = "00:01:02:03:04:05"
  data["ip"]	 = "1.1.1.1"
  data
end

#template_pool(filter = { }) ⇒ Object



87
88
89
# File 'lib/fog/opennebula/requests/compute/template_pool.rb', line 87

def template_pool(filter = { })
  [ {}, {} ]
end

#vm_allocate(attr = { }) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fog/opennebula/requests/compute/vm_allocate.rb', line 70

def vm_allocate(attr={ })
  data = {}
  data["onevm_object"] = ""
  data["status"] = "Running"
  data["state"]  = "3"
  data["id"]     = 4
  data["uuid"]   = "5"
  data["gid"]    = "5"
  data["name"]   = "MockVM"
  data["user"]   = "MockUser" 
  data["group"]  = "MockGroup"
  data["cpu"]    = "2"
  data["memory"] = "1024"
  data["mac"]	 = "00:01:02:03:04:05"
  data["ip"]	 = "1.1.1.1"
  data
end

#vm_destroy(id) ⇒ Object



16
17
18
# File 'lib/fog/opennebula/requests/compute/vm_destroy.rb', line 16

def vm_destroy(id)
  true
end