1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[opennebula] code cleanup, indentations

This commit is contained in:
Achim Ledermüller 2014-06-05 10:14:21 +02:00
parent 4e24be1f4c
commit 8f726045df

View file

@ -3,11 +3,11 @@ module Fog
class OpenNebula
class Real
def vm_allocate(attr={ })
if(attr[:flavor].nil?)
raise(ArgumentError.new("Attribute flavor is nil! #{attr.inspect}"))
end
if(attr[:name].nil? || attr[:name].empty?)
if(attr[:name].nil? || attr[:name].empty?)
raise(ArgumentError.new("Attribute name is nil or empty! #{attr.inspect}"))
end
@ -15,17 +15,17 @@ module Fog
vm = ::OpenNebula::VirtualMachine.new(xml, client)
rc = vm.allocate(attr[:flavor].to_s + "\nNAME=" + attr[:name])
# irb(main):050:0> vm.allocate(s.flavor.to_s + "\nNAME=altest5")
# => #<OpenNebula::Error:0x00000002a50760 @message="[VirtualMachineAllocate] User [42] : Not authorized to perform CREATE VM.", @errno=512>
# irb(main):051:0> a = vm.allocate(s.flavor.to_s + "\nNAME=altest5")
# => #<OpenNebula::Error:0x00000002ac0998 @message="[VirtualMachineAllocate] User [42] : Not authorized to perform CREATE VM.", @errno=512>
# irb(main):052:0> a.class
# irb(main):050:0> vm.allocate(s.flavor.to_s + "\nNAME=altest5")
# => #<OpenNebula::Error:0x00000002a50760 @message="[VirtualMachineAllocate] User [42] : Not authorized to perform CREATE VM.", @errno=512>
# irb(main):051:0> a = vm.allocate(s.flavor.to_s + "\nNAME=altest5")
# => #<OpenNebula::Error:0x00000002ac0998 @message="[VirtualMachineAllocate] User [42] : Not authorized to perform CREATE VM.", @errno=512>
# irb(main):052:0> a.class
if(rc.is_a? ::OpenNebula::Error)
if(rc.is_a? ::OpenNebula::Error)
raise(rc)
end
end
# -1 - do not change the owner
vm.chown(-1,attr[:gid].to_i) unless attr[:gid].nil?
@ -35,7 +35,7 @@ module Fog
one = vm.to_hash
data = {}
data["onevm_object"] = vm
data["onevm_object"] = vm
data["status"] = vm.state
data["state"] = vm.lcm_state_str
data["id"] = vm.id
@ -51,25 +51,25 @@ module Fog
data["memory"] = temp["MEMORY"] unless temp["MEMORY"].nil?
unless (temp["NIC"].nil?) then
if one["VM"]["TEMPLATE"]["NIC"].is_a?(Array)
data["mac"] = temp["NIC"][0]["MAC"] unless temp["NIC"][0]["MAC"].nil?
data["ip"] = temp["NIC"][0]["IP"] unless temp["NIC"][0]["IP"].nil?
data["mac"] = temp["NIC"][0]["MAC"] unless temp["NIC"][0]["MAC"].nil?
data["ip"] = temp["NIC"][0]["IP"] unless temp["NIC"][0]["IP"].nil?
else
data["mac"] = temp["NIC"]["MAC"] unless temp["NIC"]["MAC"].nil?
data["ip"] = temp["NIC"]["IP"] unless temp["NIC"]["IP"].nil?
data["mac"] = temp["NIC"]["MAC"] unless temp["NIC"]["MAC"].nil?
data["ip"] = temp["NIC"]["IP"] unless temp["NIC"]["IP"].nil?
end
end
end
data
rescue => err
raise(err)
rescue => err
raise(err)
end
end
class Mock
def vm_allocate(attr={ })
data = {}
data["onevm_object"] = ""
data["onevm_object"] = ""
data["status"] = "Running"
data["state"] = "3"
data["id"] = 4
@ -81,9 +81,9 @@ module Fog
data["cpu"] = "2"
data["memory"] = "1024"
data["mac"] = "00:01:02:03:04:05"
data["ip"] = "1.1.1.1"
data
end
data["ip"] = "1.1.1.1"
data
end
end
end
end