From 4e7055f4b7313ca8f847f8094c98d752081a3571 Mon Sep 17 00:00:00 2001 From: Cesar Felce Date: Mon, 3 Jul 2017 15:30:01 -0400 Subject: [PATCH] New Resources: lun and igroup --- libraries/netapp_api.rb | 2 +- providers/igroup.rb | 44 ++++++++++++++++++++++++++++++++++++++++ providers/lun.rb | 43 +++++++++++++++++++++++++++++++++++++++ recipes/igroup.rb | 14 +++++++++++++ recipes/lun.rb | 13 ++++++++++++ resources/igroup.rb | 16 +++++++++++++++ resources/lun.rb | 35 ++++++++++++++++++++++++++++++++ spec/helpers/matchers.rb | 15 +++++++++++++- spec/recipes/lun_spec.rb | 18 ++++++++++++++++ 9 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 providers/igroup.rb create mode 100644 providers/lun.rb create mode 100644 recipes/igroup.rb create mode 100644 recipes/lun.rb create mode 100644 resources/igroup.rb create mode 100644 resources/lun.rb create mode 100644 spec/recipes/lun_spec.rb diff --git a/libraries/netapp_api.rb b/libraries/netapp_api.rb index 9f5c3f3..eb0b05c 100644 --- a/libraries/netapp_api.rb +++ b/libraries/netapp_api.rb @@ -76,7 +76,7 @@ def invoke_api(request, svm = nil) def check_errors!(result, resource, action) if result.results_errno == 0 # The Api ran successfully and returned no error. return true - elsif result.results_errno == "17" || result.results_errno == "14922" || result.results_errno == "13130" || result.results_errno == "13080" || result.results_errno == "13001" || result.results_errno == "15698" || result.results_errno == "15661" || result.results_errno == "13040" + elsif result.results_errno == "17" || result.results_errno == "14922" || result.results_errno == "13130" || result.results_errno == "13080" || result.results_errno == "13001" || result.results_errno == "15698" || result.results_errno == "15661" || result.results_errno == "13040" || result.results_errno == "9012" #If the resource already exists, then ignore the error and proceed with the next resource. #Do not update resource count. return false diff --git a/providers/igroup.rb b/providers/igroup.rb new file mode 100644 index 0000000..2dd8c72 --- /dev/null +++ b/providers/igroup.rb @@ -0,0 +1,44 @@ +# Cookbook Name:: netapp +# Provider:: igroup +# + +include NetApp::Api + +use_inline_resources + +action :create do + + # Create API Request. + netapp_igroup_api = netapp_hash + + netapp_igroup_api[:api_name] = "igroup-create" + netapp_igroup_api[:resource] = "igroup" + netapp_igroup_api[:action] = "create" + netapp_igroup_api[:svm] = new_resource.svm + netapp_igroup_api[:api_attribute]["initiator-group-name"] = new_resource.name + netapp_igroup_api[:api_attribute]["initiator-group-type"] = new_resource.igroup_type + netapp_igroup_api[:api_attribute]["os-type"] = new_resource.ostype + + # Invoke NetApp API. + resource_update = invoke(netapp_igroup_api) + new_resource.updated_by_last_action(true) if resource_update + +end + +action :add_rule do + + # Create API Request. + netapp_igroup_add_api = netapp_hash + + netapp_igroup_add_api[:api_name] = "igroup-add" + netapp_igroup_add_api[:resource] = "igroup" + netapp_igroup_add_api[:action] = "add_rule" + netapp_igroup_add_api[:svm] = new_resource.svm + netapp_igroup_add_api[:api_attribute]["initiator-group-name"] = new_resource.name + netapp_igroup_add_api[:api_attribute]["initiator"] = new_resource.initiator + + # Invoke NetApp API. + resource_update = invoke(netapp_igroup_add_api) + new_resource.updated_by_last_action(true) if resource_update + +end diff --git a/providers/lun.rb b/providers/lun.rb new file mode 100644 index 0000000..ab4402a --- /dev/null +++ b/providers/lun.rb @@ -0,0 +1,43 @@ +# Cookbook Name:: netapp +# Provider:: lun +# +# Copyright:: 2014, Chef Software, Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include NetApp::Api + +use_inline_resources + +action :create do + + # Create API Request. + netapp_lun_create_api = netapp_hash + + netapp_lun_create_api[:api_name] = "lun-create-by-size" + netapp_lun_create_api[:resource] = "lun" + netapp_lun_create_api[:action] = "create" + netapp_lun_create_api[:svm] = new_resource.svm + netapp_lun_create_api[:api_attribute]["ostype"] = new_resource.ostype + netapp_lun_create_api[:api_attribute]["size"] = new_resource.size + netapp_lun_create_api[:api_attribute]["prefix-size"] = new_resource.psize + netapp_lun_create_api[:api_attribute]["path"] = new_resource.path + netapp_lun_create_api[:api_attribute]["comment"] = new_resource.comment + netapp_lun_create_api[:api_attribute]["space-allocation-enabled"] = new_resource.allocation + netapp_lun_create_api[:api_attribute]["space-reservation-enabled"] = new_resource.reservation + + # Invoke NetApp API. + resource_update = invoke(netapp_lun_create_api) + new_resource.updated_by_last_action(true) if resource_update + +end diff --git a/recipes/igroup.rb b/recipes/igroup.rb new file mode 100644 index 0000000..2d3c2c6 --- /dev/null +++ b/recipes/igroup.rb @@ -0,0 +1,14 @@ +#Igroup create + netapp_igroup node['igroup']['name'] do + svm node['netapp']['vserver'] + igroup_type node['igroup']['igroup_type'] + ostype node['igroup']['ostype'] + action :create + end + +#Igroup add initiator + netapp_igroup node['igroup']['name'] do + svm node['netapp']['vserver'] + initiator node['igroup']['initiator'] + action :add_rule + end diff --git a/recipes/lun.rb b/recipes/lun.rb new file mode 100644 index 0000000..593d05d --- /dev/null +++ b/recipes/lun.rb @@ -0,0 +1,13 @@ +# Cookbook Name:: netapp +# Recipe:: lun + + +#EXAMPLE CREATING ISCSI LUN VOL SHOULD EXISTS +lpath = "/vol/demo_vol/demo_lun" +netapp_lun lun do + svm node['netapp']['vserver'] + path lpath + size ((50*1024**3).to_i).to_s + ostype "linux" + action :create +end diff --git a/resources/igroup.rb b/resources/igroup.rb new file mode 100644 index 0000000..b6043f7 --- /dev/null +++ b/resources/igroup.rb @@ -0,0 +1,16 @@ +# +# Author:: Cesar Felce () +# Cookbook Name:: netapp +# Resource:: igroup +# + +actions :create, :add_rule +default_action :create + +attribute :name, :kind_of => String, :required => true, :name_attribute => true +attribute :svm, :kind_of => String + +attribute :ostype, :kind_of => String, :required => true, :equal_to => ["aix", "linux", "vmware", "windows"] +attribute :igroup_type, :kind_of => String, :required => true + +attribute :initiator, :kind_of => String, :required => true diff --git a/resources/lun.rb b/resources/lun.rb new file mode 100644 index 0000000..570bcc8 --- /dev/null +++ b/resources/lun.rb @@ -0,0 +1,35 @@ +# +# Author:: Cesar Felce () +# Cookbook Name:: netapp +# Resource:: lun +# +# Copyright:: 2014, Chef Software, Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +actions :create +default_action :create + +attribute :name, :kind_of => String, :required => true, :name_attribute => true +attribute :svm, :kind_of => String + +attribute :ostype, :kind_of => String, :required => true, :equal_to => ["aix", "linux", "vmware", "windows_2008"] +attribute :size, :kind_of => String, :required => true +attribute :psize, :kind_of => Fixnum, :required => false, :default => 512 +attribute :path, :kind_of => String, :required => true +attribute :comment, :kind_of => String, :required => false, :default => "chef" +attribute :allocation, :kind_of => String, :required => false, :default => "true" +attribute :reservation, :kind_of => String, :required => false, :default => "false" + +attribute :igroup, :kind_of => String, :required => true +attribute :id, :kind_of => String, :required => true diff --git a/spec/helpers/matchers.rb b/spec/helpers/matchers.rb index 2a387d6..cc898a7 100644 --- a/spec/helpers/matchers.rb +++ b/spec/helpers/matchers.rb @@ -102,4 +102,17 @@ def create_netapp_volume(resource_name) def delete_netapp_volume(resource_name) ChefSpec::Matchers::ResourceMatcher.new('netapp_volume', :delete, resource_name) end -end \ No newline at end of file + + def create_netapp_lun(resource_name) + ChefSpec::Matchers::ResourceMatcher.new('netapp_lun', :create, resource_name) + end + + def create_netapp_igroup(resource_name) + ChefSpec::Matchers::ResourceMatcher.new('netapp_igroup', :create, resource_name) + end + + def add_rule_netapp_igroup(resource_name) + ChefSpec::Matchers::ResourceMatcher.new('netapp_igroup', :add_rule, resource_name) + end + +end diff --git a/spec/recipes/lun_spec.rb b/spec/recipes/lun_spec.rb new file mode 100644 index 0000000..d1a4782 --- /dev/null +++ b/spec/recipes/lun_spec.rb @@ -0,0 +1,18 @@ +require_relative '../spec_helper' +require_relative '../helpers/matchers' + +describe 'netapp::lun' do + context 'without :step_into' do + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe)} + + it 'creates a new lun' do + expect(chef_run).to create_netapp_lun('demo_lun').with( + svm: "cluster2", + aggregate: "aggr1", + size: "50", #GB + ostype: "linux" + ) + end + + end +end