mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
commit
341d012f6a
12 changed files with 145 additions and 11 deletions
|
@ -57,6 +57,7 @@ An alternate file may be used by placing its path in the FOG_RC environment vari
|
||||||
:ovirt_username:
|
:ovirt_username:
|
||||||
:ovirt_password:
|
:ovirt_password:
|
||||||
:ovirt_url:
|
:ovirt_url:
|
||||||
|
:libvirt_uri:
|
||||||
:rackspace_api_key:
|
:rackspace_api_key:
|
||||||
:rackspace_username:
|
:rackspace_username:
|
||||||
:rackspace_servicenet:
|
:rackspace_servicenet:
|
||||||
|
|
|
@ -45,11 +45,29 @@ module Fog
|
||||||
request :destroy_interface
|
request :destroy_interface
|
||||||
request :get_node_info
|
request :get_node_info
|
||||||
|
|
||||||
|
module Shared
|
||||||
|
include Fog::Compute::LibvirtUtil
|
||||||
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
include Shared
|
||||||
|
def initialize(options={})
|
||||||
|
# libvirt is part of the gem => ruby-libvirt
|
||||||
|
require 'libvirt'
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
attr_reader :client
|
||||||
|
|
||||||
|
#read mocks xml
|
||||||
|
def read_xml(file_name)
|
||||||
|
file_path = File.join(File.dirname(__FILE__),"requests","compute","mock_files",file_name)
|
||||||
|
File.read(file_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Real
|
class Real
|
||||||
include Fog::Compute::LibvirtUtil
|
include Shared
|
||||||
attr_reader :client
|
attr_reader :client
|
||||||
attr_reader :uri
|
attr_reader :uri
|
||||||
attr_reader :ip_command
|
attr_reader :ip_command
|
||||||
|
|
|
@ -90,6 +90,7 @@ module Fog
|
||||||
poweroff unless stopped?
|
poweroff unless stopped?
|
||||||
connection.vm_action(uuid, :undefine)
|
connection.vm_action(uuid, :undefine)
|
||||||
volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
|
volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def reboot
|
def reboot
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def create_domain(xml)
|
def create_domain(xml)
|
||||||
|
::Libvirt::Domain.new()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def define_domain(xml)
|
def define_domain(xml)
|
||||||
|
::Libvirt::Domain.new()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,9 @@ module Fog
|
||||||
end
|
end
|
||||||
data.compact.map { |d| domain_to_attributes d }
|
data.compact.map { |d| domain_to_attributes d }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Shared
|
||||||
private
|
private
|
||||||
|
|
||||||
def vnc_port xml
|
def vnc_port xml
|
||||||
|
@ -70,8 +72,32 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def list_vms(filter = { })
|
def list_domains(filter = { })
|
||||||
|
dom1 = mock_domain 'fog-dom1'
|
||||||
|
dom2 = mock_domain 'fog-dom2'
|
||||||
|
dom3 = mock_domain 'a-fog-dom3'
|
||||||
|
[dom1, dom2, dom3]
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,17 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def list_interfaces(filters={ })
|
def list_interfaces(filters={ })
|
||||||
[]
|
if1 = mock_interface 'if1'
|
||||||
|
if2 = mock_interface 'if2'
|
||||||
|
[if1, if2]
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_interface name
|
||||||
|
{
|
||||||
|
:mac => 'aa:bb:cc:dd:ee:ff',
|
||||||
|
:name => name,
|
||||||
|
:active => true
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,17 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def list_networks(filters={ })
|
def list_networks(filters={ })
|
||||||
[]
|
net1 = mock_network 'net1'
|
||||||
|
net2 = mock_network 'net2'
|
||||||
|
[net1, net2]
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_network name
|
||||||
|
{
|
||||||
|
:uuid => 'net.uuid',
|
||||||
|
:name => name,
|
||||||
|
:bridge_name => 'net.bridge_name'
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,7 +48,23 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def list_pools(filter = { })
|
def list_pools(filter = { })
|
||||||
|
pool1 = mock_pool 'pool1'
|
||||||
|
pool2 = mock_pool 'pool1'
|
||||||
|
[pool1, pool2]
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
require 'erb'
|
|
||||||
require "rexml/document"
|
|
||||||
|
|
||||||
module Fog
|
module Fog
|
||||||
module Compute
|
module Compute
|
||||||
class Libvirt
|
class Libvirt
|
||||||
|
@ -23,8 +20,7 @@ module Fog
|
||||||
|
|
||||||
def volume_to_attributes(vol)
|
def volume_to_attributes(vol)
|
||||||
|
|
||||||
xml = REXML::Document.new(vol.xml_desc)
|
format_type = xml_element(vol.xml_desc, "/volume/target/format", "type")
|
||||||
format_type = xml.root.elements['/volume/target/format'].attributes['type']
|
|
||||||
return nil if format_type == "dir"
|
return nil if format_type == "dir"
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -70,7 +66,22 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def list_volumes(filters={ })
|
def list_volumes(filters={ })
|
||||||
|
vol1 = mock_volume 'vol1'
|
||||||
|
vol2 = mock_volume 'vol2'
|
||||||
|
[vol1, vol2]
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
40
lib/fog/libvirt/requests/compute/mock_files/domain.xml
Normal file
40
lib/fog/libvirt/requests/compute/mock_files/domain.xml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<domain type='kvm'>
|
||||||
|
<name>fog-449765558356062</name>
|
||||||
|
<memory>262144</memory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='x86_64'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
<boot dev='cdrom'/>
|
||||||
|
<boot dev='network'/>
|
||||||
|
</os>
|
||||||
|
<features>
|
||||||
|
<acpi/>
|
||||||
|
<apic/>
|
||||||
|
<pae/>
|
||||||
|
</features>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<devices>
|
||||||
|
<interface type='network'>
|
||||||
|
<mac address="aa:bb:cc:dd:ee:ff" />
|
||||||
|
<source network='net1' />
|
||||||
|
<model type='virtio'/>
|
||||||
|
</interface>
|
||||||
|
<serial type='pty'>
|
||||||
|
<target port='0'/>
|
||||||
|
</serial>
|
||||||
|
<console type='pty'>
|
||||||
|
<target port='0'/>
|
||||||
|
</console>
|
||||||
|
<input type='mouse' bus='ps2'/>
|
||||||
|
<graphics type='vnc' port='-1' autoport='yes'/>
|
||||||
|
<video>
|
||||||
|
<model type='cirrus' vram='9216' heads='1'/>
|
||||||
|
</video>
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<driver name='qemu' type='raw'/>
|
||||||
|
<source file='path/to/disk'/>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
|
@ -51,6 +51,7 @@ if Fog.mock?
|
||||||
:ovirt_url => 'http://ovirt:8080/api',
|
:ovirt_url => 'http://ovirt:8080/api',
|
||||||
:ovirt_username => 'admin@internal',
|
:ovirt_username => 'admin@internal',
|
||||||
:ovirt_password => '123123',
|
:ovirt_password => '123123',
|
||||||
|
:libvirt_uri => 'qemu://libvirt/system',
|
||||||
:rackspace_api_key => 'rackspace_api_key',
|
:rackspace_api_key => 'rackspace_api_key',
|
||||||
:rackspace_username => 'rackspace_username',
|
:rackspace_username => 'rackspace_username',
|
||||||
:slicehost_password => 'slicehost_password',
|
:slicehost_password => 'slicehost_password',
|
||||||
|
|
Loading…
Add table
Reference in a new issue