mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
added mock implementation
This commit is contained in:
parent
a7059e48dd
commit
fe0f240278
12 changed files with 144 additions and 6 deletions
|
@ -57,6 +57,7 @@ An alternate file may be used by placing its path in the FOG_RC environment vari
|
|||
:ovirt_username:
|
||||
:ovirt_password:
|
||||
:ovirt_url:
|
||||
:libvirt_uri:
|
||||
:rackspace_api_key:
|
||||
:rackspace_username:
|
||||
:rackspace_servicenet:
|
||||
|
|
|
@ -45,11 +45,29 @@ module Fog
|
|||
request :destroy_interface
|
||||
request :get_node_info
|
||||
|
||||
module Shared
|
||||
include Fog::Compute::LibvirtUtil
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
class Real
|
||||
include Fog::Compute::LibvirtUtil
|
||||
include Shared
|
||||
attr_reader :client
|
||||
attr_reader :uri
|
||||
attr_reader :ip_command
|
||||
|
|
|
@ -90,6 +90,7 @@ module Fog
|
|||
poweroff unless stopped?
|
||||
connection.vm_action(uuid, :undefine)
|
||||
volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
|
||||
true
|
||||
end
|
||||
|
||||
def reboot
|
||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_domain(xml)
|
||||
|
||||
::Libvirt::Domain.new()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def define_domain(xml)
|
||||
|
||||
::Libvirt::Domain.new()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,9 @@ module Fog
|
|||
end
|
||||
data.compact.map { |d| domain_to_attributes d }
|
||||
end
|
||||
end
|
||||
|
||||
module Shared
|
||||
private
|
||||
|
||||
def vnc_port xml
|
||||
|
@ -70,8 +72,32 @@ module Fog
|
|||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -39,7 +39,17 @@ module Fog
|
|||
|
||||
class Mock
|
||||
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
|
||||
|
|
|
@ -40,7 +40,17 @@ module Fog
|
|||
|
||||
class Mock
|
||||
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
|
||||
|
|
|
@ -48,7 +48,23 @@ module Fog
|
|||
|
||||
class Mock
|
||||
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
|
||||
|
|
|
@ -70,7 +70,22 @@ module Fog
|
|||
|
||||
class Mock
|
||||
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
|
||||
|
|
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_username => 'admin@internal',
|
||||
:ovirt_password => '123123',
|
||||
:libvirt_uri => 'qemu://libvirt/system',
|
||||
:rackspace_api_key => 'rackspace_api_key',
|
||||
:rackspace_username => 'rackspace_username',
|
||||
:slicehost_password => 'slicehost_password',
|
||||
|
|
Loading…
Reference in a new issue