Class: Fog::Libvirt::Compute::Mock

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/libvirt/compute.rb,
lib/fog/libvirt/requests/compute/vm_action.rb,
lib/fog/libvirt/requests/compute/libversion.rb,
lib/fog/libvirt/requests/compute/list_pools.rb,
lib/fog/libvirt/requests/compute/define_pool.rb,
lib/fog/libvirt/requests/compute/dhcp_leases.rb,
lib/fog/libvirt/requests/compute/pool_action.rb,
lib/fog/libvirt/requests/compute/clone_volume.rb,
lib/fog/libvirt/requests/compute/list_domains.rb,
lib/fog/libvirt/requests/compute/list_volumes.rb,
lib/fog/libvirt/requests/compute/create_domain.rb,
lib/fog/libvirt/requests/compute/create_volume.rb,
lib/fog/libvirt/requests/compute/define_domain.rb,
lib/fog/libvirt/requests/compute/get_node_info.rb,
lib/fog/libvirt/requests/compute/list_networks.rb,
lib/fog/libvirt/requests/compute/upload_volume.rb,
lib/fog/libvirt/requests/compute/volume_action.rb,
lib/fog/libvirt/requests/compute/update_display.rb,
lib/fog/libvirt/requests/compute/destroy_network.rb,
lib/fog/libvirt/requests/compute/list_interfaces.rb,
lib/fog/libvirt/requests/compute/update_autostart.rb,
lib/fog/libvirt/requests/compute/destroy_interface.rb,
lib/fog/libvirt/requests/compute/list_pool_volumes.rb

Instance Method Summary collapse

Methods included from Util

#randomized_name, #to_xml, #xml_element, #xml_elements

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



57
58
59
60
# File 'lib/fog/libvirt/compute.rb', line 57

def initialize(options={})
  # libvirt is part of the gem => ruby-libvirt
  require 'libvirt'
end

Instance Method Details

#clone_volume(pool_name, xml, name) ⇒ Object



12
13
14
# File 'lib/fog/libvirt/requests/compute/clone_volume.rb', line 12

def clone_volume(pool_name, xml, name)
  Fog::Libvirt::Compute::Volume.new({:pool_name => pool_name, :xml => xml})
end

#create_domain(xml) ⇒ Object



11
12
13
# File 'lib/fog/libvirt/requests/compute/create_domain.rb', line 11

def create_domain(xml)
  ::Libvirt::Domain.new()
end

#create_volume(pool_name, xml) ⇒ Object



11
12
# File 'lib/fog/libvirt/requests/compute/create_volume.rb', line 11

def create_volume(pool_name, xml)
end

#define_domain(xml) ⇒ Object



11
12
13
# File 'lib/fog/libvirt/requests/compute/define_domain.rb', line 11

def define_domain(xml)
  ::Libvirt::Domain.new()
end

#define_pool(xml) ⇒ Object



11
12
# File 'lib/fog/libvirt/requests/compute/define_pool.rb', line 11

def define_pool(xml)
end

#destroy_interface(uuid) ⇒ Object



12
13
14
# File 'lib/fog/libvirt/requests/compute/destroy_interface.rb', line 12

def destroy_interface(uuid)
  true
end

#destroy_network(uuid) ⇒ Object



11
12
13
# File 'lib/fog/libvirt/requests/compute/destroy_network.rb', line 11

def destroy_network(uuid)
  true
end

#dhcp_leases(uuid, mac, flags = 0) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/libvirt/requests/compute/dhcp_leases.rb', line 13

def dhcp_leases(uuid, mac, flags = 0)
  leases1 = {
    'aa:bb:cc:dd:ee:ff' => [
      { 'type' => Socket::AF_INET, 'ipaddr' => '1.2.3.4', 'prefix' => 24, 'expirytime' => 5000 },
      { 'type' => Socket::AF_INET, 'ipaddr' => '1.2.5.6', 'prefix' => 24, 'expirytime' => 5005 }
    ]
  }
  leases2 = {
    '99:88:77:66:55:44' => [
      { 'type' => Socket::AF_INET, 'ipaddr' => '10.1.1.5', 'prefix' => 24, 'expirytime' => 50 }
    ]
  }
  networks = {
    # should match mock net uuid from list_networks.rb
    'a29146ea-39b2-412d-8f53-239eef117a32' => leases1,
    'fbd4ac68-cbea-4f95-86ed-22953fd92384' => leases2
  }
  if !networks[uuid].nil?
    return networks[uuid][mac]
  end
end

#get_node_infoObject



32
33
# File 'lib/fog/libvirt/requests/compute/get_node_info.rb', line 32

def get_node_info
end

#libversionObject



12
13
14
# File 'lib/fog/libvirt/requests/compute/libversion.rb', line 12

def libversion()
  return 1002009
end

#list_domains(filter = { }) ⇒ Object



94
95
96
97
98
99
# File 'lib/fog/libvirt/requests/compute/list_domains.rb', line 94

def list_domains(filter = { })
  dom1 = mock_domain 'fog-dom1'
  dom2 = mock_domain 'fog-dom2'
  dom3 = mock_domain 'a-fog-dom3'
  [dom1, dom2, dom3]
end

#list_interfaces(filters = { }) ⇒ Object



41
42
43
44
45
# File 'lib/fog/libvirt/requests/compute/list_interfaces.rb', line 41

def list_interfaces(filters={ })
  if1 = mock_interface 'if1'
  if2 = mock_interface 'if2'
  [if1, if2]
end

#list_networks(filter = { }) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fog/libvirt/requests/compute/list_networks.rb', line 47

def list_networks(filter={ })
  networks = [ {
      :uuid        => 'a29146ea-39b2-412d-8f53-239eef117a32',
      :name        => 'net1',
      :bridge_name => 'virbr0'
    },
    {
      :uuid        => 'fbd4ac68-cbea-4f95-86ed-22953fd92384',
      :name        => 'net2',
      :bridge_name => 'virbr1'
    }
  ]
  return networks if filter.empty?

  case filter.keys.first
    when :uuid
      [networks.find(:uuid => filter[:uuid]).first]
    when :name
      [networks.find(:name => filter[:name]).first]
    else
      networks
  end
end

#list_pool_volumes(uuid) ⇒ Object



14
15
# File 'lib/fog/libvirt/requests/compute/list_pool_volumes.rb', line 14

def list_pool_volumes(uuid)
end

#list_pools(filter = { }) ⇒ Object



60
61
62
63
64
# File 'lib/fog/libvirt/requests/compute/list_pools.rb', line 60

def list_pools(filter = { })
  pool1 = mock_pool 'pool1'
  pool2 = mock_pool 'pool1'
  [pool1, pool2]
end

#list_volumes(filters = { }) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fog/libvirt/requests/compute/list_volumes.rb', line 78

def list_volumes(filters={ })
  vol1 = mock_volume 'vol1'
  vol2 = mock_volume 'vol2'
  vols = [vol1, vol2]

  if filters.keys.empty?
    return vols
  end

  key = filters.keys.first
  vols.select { |v| v[key] == filters[key] }
end

#mock_domain(name) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/fog/libvirt/requests/compute/list_domains.rb', line 101

def mock_domain name
  xml = read_xml 'domain.xml'
  {
      :id              => "dom.uuid",
      :uuid            => "dom.uuid",
      :name            => name,
      :max_memory_size => 8,
      :cputime         => 7,
      :memory_size     => 6,
      :cpus            => 5,
      :autostart       => false,
      :os_type         => "hvm",
      :active          => false,
      :vnc_port        => 5910,
      :boot_order      => boot_order(xml),
      :nics            => domain_interfaces(xml),
      :volumes_path    => domain_volumes(xml),
      :state           => 'shutoff'
  }
end

#mock_interface(name) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/fog/libvirt/requests/compute/list_interfaces.rb', line 47

def mock_interface name
  {
      :mac    => 'aa:bb:cc:dd:ee:ff',
      :name   => name,
      :active => true
  }
end

#mock_pool(name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fog/libvirt/requests/compute/list_pools.rb', line 66

def mock_pool name
  {
      :uuid           => 'pool.uuid',
      :persistent     => true,
      :autostart      => true,
      :active         => true,
      :name           => name,
      :allocation     => 123456789,
      :capacity       => 123456789,
      :num_of_volumes => 3,
      :state          => :running
  }
end

#mock_volume(name) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fog/libvirt/requests/compute/list_volumes.rb', line 91

def mock_volume name
  {
      :pool_name   => 'vol.pool.name',
      :key         => "vol.#{name}", # needs to match id
      :id          => "vol.#{name}",
      :path        => "path/to/disk", # used by in mock_files/domain.xml
      :name        => name,
      :format_type => 'raw',
      :allocation  => 123,
      :capacity    => 123,
  }
end

#pool_action(uuid, action) ⇒ Object



13
14
15
# File 'lib/fog/libvirt/requests/compute/pool_action.rb', line 13

def pool_action(uuid, action)
  true
end

#update_autostart(uuid, value) ⇒ Object



12
13
14
# File 'lib/fog/libvirt/requests/compute/update_autostart.rb', line 12

def update_autostart(uuid, value)
  value
end

#update_display(options = { }) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
# File 'lib/fog/libvirt/requests/compute/update_display.rb', line 29

def update_display(options = { })
  raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid
  true
end

#upload_volume(pool_name, volume_name, file_path) ⇒ Object



26
27
# File 'lib/fog/libvirt/requests/compute/upload_volume.rb', line 26

def upload_volume(pool_name, volume_name, file_path)
end

#vm_action(uuid, action, *params) ⇒ Object



13
14
15
# File 'lib/fog/libvirt/requests/compute/vm_action.rb', line 13

def vm_action(uuid, action, *params)
  true
end

#volume_action(action, options = {}) ⇒ Object



12
13
14
# File 'lib/fog/libvirt/requests/compute/volume_action.rb', line 12

def volume_action(action, options={})
  true
end