Merge pull request #3038 from NETWAYS/feature/improved_network_flavor_models

Feature/improved network flavor models
This commit is contained in:
Wesley Beary 2015-05-07 10:45:52 -05:00
commit 7de752a955
7 changed files with 54 additions and 14 deletions

View File

@ -51,18 +51,22 @@ module Fog
end
def get_vcpu
return "VCPU=1\n" unless vcpu
self.vcpu = 1 unless vcpu
"VCPU=#{vcpu}\n"
end
def get_memory
return "MEMORY=128\n" unless memory
self.memory = 128 unless memory
"MEMORY=#{memory}\n"
end
def get_raw
return "" unless raw
"RAW=#{raw}\n"
ret = "RAW=#{raw}\n"
ret.gsub!(/\{/, '[')
ret.gsub!(/\}/, ']')
ret.gsub!(/>/,'')
ret
end
def get_disk
@ -116,22 +120,22 @@ module Fog
def get_sched_ds_requirements
return "" unless sched_ds_requirements
%Q|SCHED_DS_REQUIREMENTS="#{sched_ds_requirements}"\n|
%Q|SCHED_DS_REQUIREMENTS="#{sched_ds_requirements.gsub(/"/){ %q(\") }}"\n|
end
def get_sched_ds_rank
return "" unless sched_ds_rank
%Q|SCHED_DS_RANK="#{sched_ds_rank}"\n|
%Q|SCHED_DS_RANK="#{sched_ds_rank.gsub(/"/){ %q(\") }}"\n|
end
def get_sched_requirements
return "" unless sched_requirements
%Q|SCHED_REQUIREMENTS="#{sched_requirements}"\n|
%Q|SCHED_REQUIREMENTS="#{sched_requirements.gsub(/"/){ %q(\") }}"\n|
end
def get_sched_rank
return "" unless sched_rank
%Q|SCHED_RANK="#{sched_rank}"\n|
%Q|SCHED_RANK="#{sched_rank.gsub(/"/){ %q(\") }}"\n|
end
def get_context

View File

@ -12,7 +12,17 @@ module Fog
end
def get(id)
self.all({:id => id}).first
data = service.list_networks({:id => id})
load(data).first
rescue Fog::Compute::OpenNebula::NotFound
nil
end
def get_by_name(network)
data = service.list_networks({:network => network})
load(data).first
rescue Fog::Compute::OpenNebula::NotFound
nil
end
def get_by_filter(filter)

View File

@ -50,7 +50,7 @@ module Fog
class Mock
def list_networks(filters={})
net1 = mock_network 'net1'
net1 = mock_network 'fogtest'
net2 = mock_network 'net2'
[net1, net2]
end

View File

@ -63,9 +63,14 @@ module Fog
h["NIC"] = [] # reset nics to a array
if nics.is_a? Array
nics.each do |n|
n["model"] = "virtio" if n["model"].nil?
n["uuid"] = "0" if n["uuid"].nil? # is it better is to remove this NIC?
h["NIC"] << interfaces.new({ :vnet => networks.get(n["uuid"]), :model => n["model"]})
if n["NETWORK_ID"]
vnet = networks.get(n["NETWORK_ID"].to_s)
elsif n["NETWORK"]
vnet = networks.get_by_name(n["NETWORK"].to_s)
else
next
end
h["NIC"] << interfaces.new({ :vnet => vnet, :model => n["MODEL"] || "virtio" })
end
elsif nics.is_a? Hash
nics["model"] = "virtio" if nics["model"].nil?
@ -82,7 +87,6 @@ module Fog
else
# should i break?
end
# every key should be lowercase
ret_hash = {}
@ -100,6 +104,9 @@ module Fog
class Mock
def template_pool(filter = { })
nic1 = Mock_nic.new
nic1.vnet = networks.first
[
{
:content => %Q{
@ -119,6 +126,7 @@ module Fog
:sched_ds_rank => "FREE_MB",
:disk => {},
:nic => {},
:nic => [ nic1 ] ,
:os => {
'ARCH' => 'x86_64'
},
@ -129,6 +137,17 @@ module Fog
}
]
end
class Mock_nic
attr_accessor :vnet
def id
2
end
def name
"fogtest"
end
end
end #class Mock
end #class OpenNebula
end #module Compute

View File

@ -24,6 +24,13 @@ Shindo.tests('Fog::Compute[:opennebula] | flavor model', ['opennebula']) do
end
end
test('be a kind of Fog::Compute::OpenNebula::Flavor') { flavor.kind_of? Fog::Compute::OpenNebula::Flavor }
test('have a nic in network fogtest') { flavor.nic[0].vnet.name == "fogtest" }
flavor.vcpu = 666
flavor.memory = 666
test('have a 666 MB memory') { flavor.get_memory == "MEMORY=666\n" }
test('have a 666 CPUs') { flavor.get_vcpu == "VCPU=666\n" }
end
end

View File

@ -13,5 +13,4 @@ Shindo.tests('Fog::Compute[:opennebula] | flavors collection', ['opennebula']) d
tests('by filter').succeeds { flavors.get_by_filter ({:name => "fogtest", :id => flavors.first.id }) }
end
end
end

View File

@ -9,6 +9,7 @@ Shindo.tests('Fog::Compute[:opennebula] | networks collection', ['opennebula'])
tests('all').succeeds { networks.all }
tests('by instance id').succeeds { networks.get networks.first.id }
tests('by filter').succeeds { networks.get_by_filter ({ :id => networks.first.id }) }
tests('by name').succeeds { networks.get_by_name ("fogtest") }
end
end