Class: Fog::Compute::Libvirt::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/list_pools.rb,
lib/fog/libvirt/requests/compute/define_pool.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/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/destroy_interface.rb,
lib/fog/libvirt/requests/compute/list_pool_volumes.rb

Instance Method Summary collapse

Methods included from Fog::Compute::LibvirtUtil

#randomized_name, #to_xml, #xml_element, #xml_elements

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



54
55
56
57
# File 'lib/fog/libvirt/compute.rb', line 54

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::Compute::Libvirt::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

#get_node_infoObject



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

def get_node_info
end

#list_domains(filter = { }) ⇒ Object



75
76
77
78
79
80
# File 'lib/fog/libvirt/requests/compute/list_domains.rb', line 75

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(filters = { }) ⇒ Object



39
40
41
42
43
# File 'lib/fog/libvirt/requests/compute/list_networks.rb', line 39

def list_networks(filters={ })
  net1 = mock_network 'net1'
  net2 = mock_network 'net2'
  [net1, net2]
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



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

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

#list_volumes(filters = { }) ⇒ Object



67
68
69
70
71
# File 'lib/fog/libvirt/requests/compute/list_volumes.rb', line 67

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

#mock_domain(name) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fog/libvirt/requests/compute/list_domains.rb', line 82

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         => "RHEL6",
      :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_network(name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/fog/libvirt/requests/compute/list_networks.rb', line 45

def mock_network name
  {
      :uuid        => 'net.uuid',
      :name        => name,
      :bridge_name => 'net.bridge_name'
  }
end

#mock_pool(name) ⇒ Object



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

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



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/libvirt/requests/compute/list_volumes.rb', line 73

def mock_volume name
  {
      :pool_name   => 'vol.pool.name',
      :key         => 'vol.key',
      :id          => 'vol.key',
      :path        => 'vol.path',
      :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_display(options = { }) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/fog/libvirt/requests/compute/update_display.rb', line 24

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

#vm_action(uuid, action) ⇒ Object



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

def vm_action(uuid, action)
  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