Scott Seago
2009-May-15 20:16 UTC
[Ovirt-devel] [PATCH server] provide default uuid and mac if not provided for create.
Signed-off-by: Scott Seago <sseago at redhat.com> --- src/app/services/vm_service.rb | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/services/vm_service.rb b/src/app/services/vm_service.rb index 4c29bcf..47ac5f5 100644 --- a/src/app/services/vm_service.rb +++ b/src/app/services/vm_service.rb @@ -52,15 +52,9 @@ module VmService def svc_new(vm_resource_pool_id) raise ActionError.new("VM Resource Pool is required.") unless vm_resource_pool_id - # random MAC - mac = [ 0x00, 0x16, 0x3e, rand(0x7f), rand(0xff), rand(0xff) ] - # random uuid - uuid = ["%02x"*4, "%02x"*2, "%02x"*2, "%02x"*2, "%02x"*6].join("-") % - Array.new(16) {|x| rand(0xff) } - - @vm = Vm.new({:vm_resource_pool_id => vm_resource_pool_id, - :vnic_mac_addr => mac.collect {|x| "%02x" % x}.join(":"), - :uuid => uuid }) + new_vm_hash = {:vm_resource_pool_id => vm_resource_pool_id} + default_mac_and_uuid(new_vm_hash) + @vm = Vm.new(new_vm_hash) authorized!(Privilege::MODIFY, @vm.vm_resource_pool) end @@ -71,6 +65,7 @@ module VmService # === Required permissions # [<tt>Privilege::MODIFY</tt>] for the vm's VmResourcePool def svc_create(vm_hash, start_now) + default_mac_and_uuid(vm_hash) vm_hash[:state] = Vm::STATE_PENDING @vm = Vm.new(vm_hash) authorized!(Privilege::MODIFY, at vm.vm_resource_pool) @@ -250,4 +245,16 @@ module VmService authorized!(priv, at vm.vm_resource_pool) end + def default_mac_and_uuid(vm_hash) + unless vm_hash[:uuid] + vm_hash[:uuid] = ["%02x"*4, "%02x"*2, "%02x"*2, + "%02x"*2, "%02x"*6].join("-") % + Array.new(16) {|x| rand(0xff) } + end + unless vm_hash[:mac] + vm_hash[:mac] = [ 0x00, 0x16, 0x3e, rand(0x7f), rand(0xff), + rand(0xff) ].collect {|x| "%02x" % x}.join(":") + end + end + end -- 1.6.0.6
Scott Seago
2009-May-18 18:23 UTC
[Ovirt-devel] [PATCH server] provide default uuid and mac if not provided for create.
Signed-off-by: Scott Seago <sseago at redhat.com> --- src/app/services/vm_service.rb | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/services/vm_service.rb b/src/app/services/vm_service.rb index 4c29bcf..cfb3c5f 100644 --- a/src/app/services/vm_service.rb +++ b/src/app/services/vm_service.rb @@ -52,15 +52,9 @@ module VmService def svc_new(vm_resource_pool_id) raise ActionError.new("VM Resource Pool is required.") unless vm_resource_pool_id - # random MAC - mac = [ 0x00, 0x16, 0x3e, rand(0x7f), rand(0xff), rand(0xff) ] - # random uuid - uuid = ["%02x"*4, "%02x"*2, "%02x"*2, "%02x"*2, "%02x"*6].join("-") % - Array.new(16) {|x| rand(0xff) } - - @vm = Vm.new({:vm_resource_pool_id => vm_resource_pool_id, - :vnic_mac_addr => mac.collect {|x| "%02x" % x}.join(":"), - :uuid => uuid }) + new_vm_hash = {:vm_resource_pool_id => vm_resource_pool_id} + default_mac_and_uuid(new_vm_hash) + @vm = Vm.new(new_vm_hash) authorized!(Privilege::MODIFY, @vm.vm_resource_pool) end @@ -71,6 +65,7 @@ module VmService # === Required permissions # [<tt>Privilege::MODIFY</tt>] for the vm's VmResourcePool def svc_create(vm_hash, start_now) + default_mac_and_uuid(vm_hash) vm_hash[:state] = Vm::STATE_PENDING @vm = Vm.new(vm_hash) authorized!(Privilege::MODIFY, at vm.vm_resource_pool) @@ -250,4 +245,16 @@ module VmService authorized!(priv, at vm.vm_resource_pool) end + def default_mac_and_uuid(vm_hash) + unless vm_hash[:uuid] + vm_hash[:uuid] = ["%02x"*4, "%02x"*2, "%02x"*2, + "%02x"*2, "%02x"*6].join("-") % + Array.new(16) {|x| rand(0xff) } + end + unless vm_hash[:vnic_mac_addr] + vm_hash[:vnic_mac_addr] = [ 0x00, 0x16, 0x3e, rand(0x7f), rand(0xff), + rand(0xff) ].collect {|x| "%02x" % x}.join(":") + end + end + end -- 1.6.0.6
Reasonably Related Threads
- permit many-to-many vms / networks relationship redux
- permit many-to-many vms / networks relationship
- [PATCH server] permit many-to-many vms / networks relationship
- [PATCH server] final cleanup for service layer refactoring.
- [PATCH server] Starting of new ovirt QMF API.