Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
New Resources: lun and igroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Felce committed Jul 3, 2017
1 parent b2c09c1 commit 4e7055f
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libraries/netapp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions providers/igroup.rb
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions providers/lun.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Cookbook Name:: netapp
# Provider:: lun
#
# Copyright:: 2014, Chef Software, Inc <[email protected]>
#
# 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
14 changes: 14 additions & 0 deletions recipes/igroup.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions recipes/lun.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions resources/igroup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Author:: Cesar Felce (<[email protected]>)
# 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
35 changes: 35 additions & 0 deletions resources/lun.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Author:: Cesar Felce (<[email protected]>)
# Cookbook Name:: netapp
# Resource:: lun
#
# Copyright:: 2014, Chef Software, Inc <[email protected]>
#
# 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
15 changes: 14 additions & 1 deletion spec/helpers/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
18 changes: 18 additions & 0 deletions spec/recipes/lun_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e7055f

Please sign in to comment.