mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #3038 from NETWAYS/feature/improved_network_flavor_models
Feature/improved network flavor models
This commit is contained in:
commit
7de752a955
7 changed files with 54 additions and 14 deletions
|
@ -51,18 +51,22 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_vcpu
|
def get_vcpu
|
||||||
return "VCPU=1\n" unless vcpu
|
self.vcpu = 1 unless vcpu
|
||||||
"VCPU=#{vcpu}\n"
|
"VCPU=#{vcpu}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_memory
|
def get_memory
|
||||||
return "MEMORY=128\n" unless memory
|
self.memory = 128 unless memory
|
||||||
"MEMORY=#{memory}\n"
|
"MEMORY=#{memory}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_raw
|
def get_raw
|
||||||
return "" unless raw
|
return "" unless raw
|
||||||
"RAW=#{raw}\n"
|
ret = "RAW=#{raw}\n"
|
||||||
|
ret.gsub!(/\{/, '[')
|
||||||
|
ret.gsub!(/\}/, ']')
|
||||||
|
ret.gsub!(/>/,'')
|
||||||
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_disk
|
def get_disk
|
||||||
|
@ -116,22 +120,22 @@ module Fog
|
||||||
|
|
||||||
def get_sched_ds_requirements
|
def get_sched_ds_requirements
|
||||||
return "" unless 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
|
end
|
||||||
|
|
||||||
def get_sched_ds_rank
|
def get_sched_ds_rank
|
||||||
return "" unless 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
|
end
|
||||||
|
|
||||||
def get_sched_requirements
|
def get_sched_requirements
|
||||||
return "" unless sched_requirements
|
return "" unless sched_requirements
|
||||||
%Q|SCHED_REQUIREMENTS="#{sched_requirements}"\n|
|
%Q|SCHED_REQUIREMENTS="#{sched_requirements.gsub(/"/){ %q(\") }}"\n|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_sched_rank
|
def get_sched_rank
|
||||||
return "" unless sched_rank
|
return "" unless sched_rank
|
||||||
%Q|SCHED_RANK="#{sched_rank}"\n|
|
%Q|SCHED_RANK="#{sched_rank.gsub(/"/){ %q(\") }}"\n|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_context
|
def get_context
|
||||||
|
|
|
@ -12,7 +12,17 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(id)
|
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
|
end
|
||||||
|
|
||||||
def get_by_filter(filter)
|
def get_by_filter(filter)
|
||||||
|
|
|
@ -50,7 +50,7 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def list_networks(filters={})
|
def list_networks(filters={})
|
||||||
net1 = mock_network 'net1'
|
net1 = mock_network 'fogtest'
|
||||||
net2 = mock_network 'net2'
|
net2 = mock_network 'net2'
|
||||||
[net1, net2]
|
[net1, net2]
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,9 +63,14 @@ module Fog
|
||||||
h["NIC"] = [] # reset nics to a array
|
h["NIC"] = [] # reset nics to a array
|
||||||
if nics.is_a? Array
|
if nics.is_a? Array
|
||||||
nics.each do |n|
|
nics.each do |n|
|
||||||
n["model"] = "virtio" if n["model"].nil?
|
if n["NETWORK_ID"]
|
||||||
n["uuid"] = "0" if n["uuid"].nil? # is it better is to remove this NIC?
|
vnet = networks.get(n["NETWORK_ID"].to_s)
|
||||||
h["NIC"] << interfaces.new({ :vnet => networks.get(n["uuid"]), :model => n["model"]})
|
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
|
end
|
||||||
elsif nics.is_a? Hash
|
elsif nics.is_a? Hash
|
||||||
nics["model"] = "virtio" if nics["model"].nil?
|
nics["model"] = "virtio" if nics["model"].nil?
|
||||||
|
@ -82,7 +87,6 @@ module Fog
|
||||||
else
|
else
|
||||||
# should i break?
|
# should i break?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# every key should be lowercase
|
# every key should be lowercase
|
||||||
ret_hash = {}
|
ret_hash = {}
|
||||||
|
@ -100,6 +104,9 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def template_pool(filter = { })
|
def template_pool(filter = { })
|
||||||
|
nic1 = Mock_nic.new
|
||||||
|
nic1.vnet = networks.first
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
:content => %Q{
|
:content => %Q{
|
||||||
|
@ -119,6 +126,7 @@ module Fog
|
||||||
:sched_ds_rank => "FREE_MB",
|
:sched_ds_rank => "FREE_MB",
|
||||||
:disk => {},
|
:disk => {},
|
||||||
:nic => {},
|
:nic => {},
|
||||||
|
:nic => [ nic1 ] ,
|
||||||
:os => {
|
:os => {
|
||||||
'ARCH' => 'x86_64'
|
'ARCH' => 'x86_64'
|
||||||
},
|
},
|
||||||
|
@ -129,6 +137,17 @@ module Fog
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Mock_nic
|
||||||
|
attr_accessor :vnet
|
||||||
|
|
||||||
|
def id
|
||||||
|
2
|
||||||
|
end
|
||||||
|
def name
|
||||||
|
"fogtest"
|
||||||
|
end
|
||||||
|
end
|
||||||
end #class Mock
|
end #class Mock
|
||||||
end #class OpenNebula
|
end #class OpenNebula
|
||||||
end #module Compute
|
end #module Compute
|
||||||
|
|
|
@ -24,6 +24,13 @@ Shindo.tests('Fog::Compute[:opennebula] | flavor model', ['opennebula']) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
test('be a kind of Fog::Compute::OpenNebula::Flavor') { flavor.kind_of? Fog::Compute::OpenNebula::Flavor }
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -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 }) }
|
tests('by filter').succeeds { flavors.get_by_filter ({:name => "fogtest", :id => flavors.first.id }) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ Shindo.tests('Fog::Compute[:opennebula] | networks collection', ['opennebula'])
|
||||||
tests('all').succeeds { networks.all }
|
tests('all').succeeds { networks.all }
|
||||||
tests('by instance id').succeeds { networks.get networks.first.id }
|
tests('by instance id').succeeds { networks.get networks.first.id }
|
||||||
tests('by filter').succeeds { networks.get_by_filter ({ :id => 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue