-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from dcbw/ipaddr-libvirt
Retrieve VM IP address using libvirt
- Loading branch information
Showing
9 changed files
with
87 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'socket' | ||
|
||
module Fog | ||
module Compute | ||
class Libvirt | ||
class Real | ||
def dhcp_leases(uuid, mac, flags = 0) | ||
client.lookup_network_by_uuid(uuid).dhcp_leases(mac, flags) | ||
end | ||
end | ||
|
||
class Mock | ||
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 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Shindo.tests("Fog::Compute[:libvirt] | dhcp_leases request", 'libvirt') do | ||
|
||
compute = Fog::Compute[:libvirt] | ||
|
||
tests("DHCP leases response") do | ||
response = compute.dhcp_leases("fbd4ac68-cbea-4f95-86ed-22953fd92384", "99:88:77:66:55:44", 0) | ||
test("should be an array") { response.kind_of? Array } | ||
test("should have one element") { response.length == 1 } | ||
test("should have dict elements") { response[0].kind_of? Hash } | ||
["ipaddr", "prefix", "expirytime", "type"].each { | ||
|k| test("should have dict elements with required key #{k}") { !response[0][k].nil? } | ||
} | ||
end | ||
|
||
end |