From 0f3e7f08c6bd49b99789758c9921dadd6a351dd7 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 17:10:28 +0200 Subject: [PATCH] refactor providers - refactor prefatch method --- lib/puppet/provider/onecluster/cli.rb | 5 ++--- lib/puppet/provider/onedatastore/cli.rb | 5 ++--- lib/puppet/provider/onehost/cli.rb | 5 ++--- lib/puppet/provider/oneimage/cli.rb | 5 ++--- lib/puppet/provider/onesecgroup/cli.rb | 5 ++--- lib/puppet/provider/onevm/cli.rb | 7 +++---- lib/puppet/provider/onevnet_addressrange/cli.rb | 5 ++--- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/puppet/provider/onecluster/cli.rb b/lib/puppet/provider/onecluster/cli.rb index 2c80bfcf..024ecd5d 100644 --- a/lib/puppet/provider/onecluster/cli.rb +++ b/lib/puppet/provider/onecluster/cli.rb @@ -98,9 +98,8 @@ def self.instances def self.prefetch(resources) clusters = instances resources.keys.each do |name| - if provider = clusters.find{ |cluster| cluster.name == name } - resources[name].provider = provider - end + provider = clusters.find{ |cluster| cluster.name == name } + resources[name].provider = provider unless provider.nil? end end diff --git a/lib/puppet/provider/onedatastore/cli.rb b/lib/puppet/provider/onedatastore/cli.rb index a2a7ae20..ec294daf 100644 --- a/lib/puppet/provider/onedatastore/cli.rb +++ b/lib/puppet/provider/onedatastore/cli.rb @@ -90,9 +90,8 @@ def self.instances def self.prefetch(resources) datastores = instances resources.keys.each do |name| - if provider = datastores.find{ |datastore| datastore.name == name } - resources[name].provider = provider - end + provider = datastores.find{ |datastore| datastore.name == name } + resources[name].provider = provider unless provider.nil? end end diff --git a/lib/puppet/provider/onehost/cli.rb b/lib/puppet/provider/onehost/cli.rb index 6c4d635d..b9b68167 100644 --- a/lib/puppet/provider/onehost/cli.rb +++ b/lib/puppet/provider/onehost/cli.rb @@ -53,9 +53,8 @@ def self.instances def self.prefetch(resources) hosts = instances resources.keys.each do |name| - if provider = hosts.find{ |host| host.name == name } - resources[name].provider = provider - end + provider = hosts.find{ |host| host.name == name } + resources[name].provider = provider unless provider.nil? end end diff --git a/lib/puppet/provider/oneimage/cli.rb b/lib/puppet/provider/oneimage/cli.rb index 4ba6ad74..8cd26824 100644 --- a/lib/puppet/provider/oneimage/cli.rb +++ b/lib/puppet/provider/oneimage/cli.rb @@ -105,9 +105,8 @@ def self.instances def self.prefetch(resources) images = instances resources.keys.each do |name| - if provider = images.find{ |image| image.name == name } - resources[name].provider = provider - end + provider = images.find{ |image| image.name == name } + resources[name].provider = provider unless provider.nil? end end diff --git a/lib/puppet/provider/onesecgroup/cli.rb b/lib/puppet/provider/onesecgroup/cli.rb index 0a28f4d8..6a6dca1a 100644 --- a/lib/puppet/provider/onesecgroup/cli.rb +++ b/lib/puppet/provider/onesecgroup/cli.rb @@ -83,9 +83,8 @@ def self.instances def self.prefetch(resources) secgroups = instances resources.keys.each do |name| - if provider = secgroups.find{ |secgroup| secgroup.name == name } - resources[name].provider = provider - end + provider = secgroups.find{ |secgroup| secgroup.name == name } + resources[name].provider = provider unless provider.nil? end end diff --git a/lib/puppet/provider/onevm/cli.rb b/lib/puppet/provider/onevm/cli.rb index e3b142b0..e291f080 100644 --- a/lib/puppet/provider/onevm/cli.rb +++ b/lib/puppet/provider/onevm/cli.rb @@ -63,14 +63,13 @@ def self.instances def self.prefetch(resources) vms = instances resources.keys.each do |name| - if provider = vms.find{ |vm| vm.name == name } - resources[name].provider = provider - end + provider = vms.find{ |vm| vm.name == name } + resources[name].provider = provider unless provider.nil? end end # setters def template=(value) - raise "Can not modify a VM template" + raise 'Can not modify a VM template' end end diff --git a/lib/puppet/provider/onevnet_addressrange/cli.rb b/lib/puppet/provider/onevnet_addressrange/cli.rb index 72671403..b18d1b05 100644 --- a/lib/puppet/provider/onevnet_addressrange/cli.rb +++ b/lib/puppet/provider/onevnet_addressrange/cli.rb @@ -84,9 +84,8 @@ def self.instances def self.prefetch(resources) vnets = instances resources.keys.each do |name| - if provider = vnets.find{ |vnet| vnet.name == name } - resources[name].provider = provider - end + provider = vnets.find{ |vnet| vnet.name == name } + resources[name].provider = provider unless provider.nil? end end