From d2930c27fa9de450b301c5ede40bf3ca76b6bac9 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 10:31:34 +0200 Subject: [PATCH 1/6] 4.12 is now standard, don't need to set it here - if we are going to 4.14 this will fail. --- spec/acceptance/onesecgroup_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/acceptance/onesecgroup_spec.rb b/spec/acceptance/onesecgroup_spec.rb index 7d071e26..47cc0fc9 100644 --- a/spec/acceptance/onesecgroup_spec.rb +++ b/spec/acceptance/onesecgroup_spec.rb @@ -4,8 +4,7 @@ before :all do pp =<<-EOS class { 'one': - oned => true, - one_version => '4.12', + oned => true, } EOS apply_manifest(pp, :catch_failures => true) From 4b9b0d7cdb9b2382437b3001e0f9007fd71a45be Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 11:28:25 +0200 Subject: [PATCH 2/6] fix test for onevnet - let ar use the vnet of its own test --- spec/acceptance/onevnet_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/onevnet_spec.rb b/spec/acceptance/onevnet_spec.rb index 682b21cc..0b7b136b 100644 --- a/spec/acceptance/onevnet_spec.rb +++ b/spec/acceptance/onevnet_spec.rb @@ -73,7 +73,7 @@ class { 'one': onevnet_addressrange { 'ar3': ensure => present, - onevnet_name => 'vnet2', + onevnet_name => 'vnet3', protocol => ip6, ip_size => '10', mac => '02:00:0a:00:00:96', From f8e2830bc2ad8f8ead3ff620cec5fac86c8c6bcd Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 11:29:13 +0200 Subject: [PATCH 3/6] fix onevnet_addressrange provider - use the right reference to ar_id --- lib/puppet/provider/onevnet_addressrange/cli.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/onevnet_addressrange/cli.rb b/lib/puppet/provider/onevnet_addressrange/cli.rb index e41f0f80..72671403 100644 --- a/lib/puppet/provider/onevnet_addressrange/cli.rb +++ b/lib/puppet/provider/onevnet_addressrange/cli.rb @@ -109,12 +109,14 @@ def flush end end }.map{|a| "#{a[0]} = #{a[1]}," unless a.nil? }.join("\n") - file << "AR_ID = #{ar_id}" unless ar_id.nil? + file << "AR_ID = #{resource[:ar_id]}" unless resource[:ar_id].nil? file << ']' file.close self.debug(IO.read file.path) self.debug(@property_hash) - onevnet('updatear', resource[:onevnet_name], ar_id, file.path ) unless ( @property_hash.empty? or ar_id.nil? or !defined? ar_id ) + unless @property_hash.empty? or resource[:ar_id].nil? or not defined? resource[:ar_id] + onevnet('updatear', resource[:onevnet_name], resource[:ar_id], file.path) + end file.delete end From 64fd4dc1f180c04c1a5e072e48c1261e56305374 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 16:11:19 +0200 Subject: [PATCH 4/6] fix onevnet provider - change the initial xml to create a vnet - reformat code --- lib/puppet/provider/onevnet/cli.rb | 116 +++++++++++------------------ 1 file changed, 42 insertions(+), 74 deletions(-) diff --git a/lib/puppet/provider/onevnet/cli.rb b/lib/puppet/provider/onevnet/cli.rb index e9d37008..fe380b8d 100644 --- a/lib/puppet/provider/onevnet/cli.rb +++ b/lib/puppet/provider/onevnet/cli.rb @@ -11,15 +11,13 @@ # Deutsche Post E-POST Development GmbH - 2014, 2015 # -#require 'pry' - require 'rubygems' require 'nokogiri' Puppet::Type.type(:onevnet).provide(:cli) do - desc "onevnet provider" + desc 'onevnet provider' - has_command(:onevnet, "onevnet") do + has_command(:onevnet, 'onevnet') do environment :HOME => '/root', :ONE_AUTH => '/var/lib/one/.one/one_auth' end @@ -29,44 +27,18 @@ def create file = Tempfile.new("onevnet-#{resource[:name]}") builder = Nokogiri::XML::Builder.new do |xml| - xml.VNET do - xml.NAME resource[:name] - xml.BRIDGE resource[:bridge] - xml.PHYDEV do - resource[:phydev] - end if resource[:phydev] - xml.VLAN_ID do - resource[:vlanid] - end if resource[:vlanid] - xml.TEMPLATE do - xml.DNS do - resource[:dnsservers] - end - end if resource[:dnsservers] - xml.TEMPLATE do - xml.GATEWAY do - resource[:gateway] - end - end if resource[:gateway] - xml.TEMPLATE do - xml.NETWORK_MASK do - resource[:netmask] - end - end if resource[:netmask] - xml.TEMPLATE do - xml.NETWORK_ADDRESS do - resource[:network_address] - end - end if resource[:network_address] - xml.CONTEXT do - resource[:context].each do |k,v| - xml.send(k.upcase, v) - end if resource[:context] - end - end - # end xml vnet do + xml.VNET do + xml.NAME resource[:name] + xml.BRIDGE resource[:bridge] + xml.PHYDEV resource[:phydev] if resource[:phydev] + xml.VLAN_ID resource[:vlanid] if resource[:vlanid] + xml.DNS resource[:dnsservers].join(' ') if resource[:dnsservers] + xml.GATEWAY resource[:gateway] if resource[:gateway] + xml.NETWORK_MASK resource[:netmask] if resource[:netmask] + xml.NETWORK_ADDRESS resource[:network_address] if resource[:network_address] + xml.CONTEXT resource[:context].each { |k, v| xml.send(k.upcase, v) } if resource[:context] + end end - # end builder tempfile = builder.to_xml file.write(tempfile) file.close @@ -89,31 +61,29 @@ def exists? # Return the full hash of all existing onevnet resources def self.instances - vnets = Nokogiri::XML(onevnet('list','-x')).root.xpath('/VNET_POOL/VNET') -#pry.binding - vnets.collect do |vnet| - new( - :name => vnet.xpath('./NAME').text, - :ensure => :present, - :bridge => vnet.xpath('./BRIDGE').text, - :context => nil, - :dnsservers => (vnet.xpath('./TEMPLATE/DNS').text.split(" ") unless vnet.xpath('./TEMPLATE/DNS').nil?), - :gateway => (vnet.xpath('./TEMPLATE/GATEWAY').text unless vnet.xpath('./TEMPLATE/GATEWAY').nil?), - :netmask => (vnet.xpath('./TEMPLATE/NETWORK_MASK').text unless vnet.xpath('./TEMPLATE/NETWORK_MASK').nil?), - :network_address => (vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').text unless vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').nil?), - :model => (vnet.xpath('./TEMPLATE/MODEL').text unless vnet.xpath('./TEMPLATE/MODEL').nil?), - :phydev => vnet.xpath('./PHYDEV').text, - :vlanid => vnet.xpath('./VLAN_ID').text - ) - end + vnets = Nokogiri::XML(onevnet('list', '-x')).root.xpath('/VNET_POOL/VNET') + vnets.collect do |vnet| + new( + :ensure => :present, + :name => vnet.xpath('./NAME').text, + :bridge => vnet.xpath('./BRIDGE').text, + :phydev => vnet.xpath('./PHYDEV').text, + :vlanid => vnet.xpath('./VLAN_ID').text, + :context => nil, + :dnsservers => (vnet.xpath('./TEMPLATE/DNS').text.split(' ') unless vnet.xpath('./TEMPLATE/DNS').nil?), + :gateway => (vnet.xpath('./TEMPLATE/GATEWAY').text unless vnet.xpath('./TEMPLATE/GATEWAY').nil?), + :netmask => (vnet.xpath('./TEMPLATE/NETWORK_MASK').text unless vnet.xpath('./TEMPLATE/NETWORK_MASK').nil?), + :network_address => (vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').text unless vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').nil?), + :model => (vnet.xpath('./TEMPLATE/MODEL').text unless vnet.xpath('./TEMPLATE/MODEL').nil?) + ) + end end 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 @@ -122,24 +92,22 @@ def flush file << @property_hash.map { |k, v| unless resource[k].nil? or resource[k].to_s.empty? or [:name, :provider, :ensure].include?(k) case k - when :vlanid - [ 'VLAN_ID', v ] - when :addressrange - k.each_pair do |key, value| - end - when :dnsservers - [ 'DNS', "\"#{v.join(" ")}\"" ] - when :netmask - [ 'NETWORK_MASK', v ] - else - [ k.to_s.upcase, v ] + when :vlanid + ['VLAN_ID', v] + when :addressrange + k.each_pair { |key, value|} + when :dnsservers + ['DNS', "\"#{v.join(' ')}\""] + when :netmask + ['NETWORK_MASK', v] + else + [k.to_s.upcase, v] end end - }.map{|a| "#{a[0]} = #{a[1]}" unless a.nil? }.join("\n") + }.map { |a| "#{a[0]} = #{a[1]}" unless a.nil? }.join("\n") file.close self.debug(IO.read file.path) onevnet('update', resource[:name], file.path, '--append') unless @property_hash.empty? file.delete end - end From b0d642aed5e6846d29e877f60de2c50fa8066cc2 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 17:00:00 +0200 Subject: [PATCH 5/6] fix provider - add templatefile definition - reformat code --- lib/puppet/provider/onetemplate/cli.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/onetemplate/cli.rb b/lib/puppet/provider/onetemplate/cli.rb index 5c6c49ad..dc1f7942 100644 --- a/lib/puppet/provider/onetemplate/cli.rb +++ b/lib/puppet/provider/onetemplate/cli.rb @@ -71,6 +71,7 @@ def create end if resource[:context] end end + tempfile = builder.to_xml file.write(tempfile) file.close self.debug "Creating template using #{tempfile}" @@ -114,9 +115,8 @@ def self.instances def self.prefetch(resources) templates = instances resources.keys.each do |name| - if provider = templates.find{ |template| template.name == name } - resources[name].provider = provider - end + provider = templates.find { |template| template.name == name } + resources[name].provider = provider unless provider.nil? end end From 0f3e7f08c6bd49b99789758c9921dadd6a351dd7 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 3 Sep 2015 17:10:28 +0200 Subject: [PATCH 6/6] 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