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/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.



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

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

Instance Method Details

#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(xml) ⇒ Object



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

def create_volume(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
13
# 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



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

def get_node_info

end

#list_domains(filter = { }) ⇒ Object



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

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



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

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

#list_networks(filters = { }) ⇒ Object



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

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

#list_pool_volumes(uuid) ⇒ Object



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

def list_pool_volumes(uuid)

end

#list_pools(filter = { }) ⇒ Object



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

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

#list_volumes(filters = { }) ⇒ Object



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

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

#mock_domain(name) ⇒ Object



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

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,
      :vcpus           => 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



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

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

#mock_network(name) ⇒ Object



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

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

#mock_pool(name) ⇒ Object



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

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



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

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.has_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