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 4e7055f commit 617f42e
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 85 deletions.
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ This resource has the following actions:
### Attributes ###
This resource has the following attributes:

* `name` name attribute. Required. SVM names can contain a period (.), a hyphen (-), or an underscore (_), but must not start with a hyphen, period, or number. The maximum number of characters allowed in SVM names is 47.
* `name` name attribute. Required. SVM names can contain a period (.), a hyphen (-), or an underscore ( _ ), but must not start with a hyphen, period, or number. The maximum number of characters allowed in SVM names is 47.
* `nsswitch` Required.
* `volume` Required
* `aggregate` Required. Aggregate on which you want to create the root volume for the SVM. The default aggregate name is used if you do not specify one.
Expand Down Expand Up @@ -423,6 +423,92 @@ netapp_role '/bar' do
end
````

netapp_igroup
------------
SVM-management of igroup creation. Creating the igroup and the initiator is a pre-requisite for the lun.

### Actions ###
This resource has the following actions:

* `:create` Default.
* `:add_rule` add rule to the igroup

### Attributes ###
This resource has the following attributes:

* `name` string, name attribute. Volume name. Required.
* `svm` string. Name of managed SVM. Required
* `ostype` string. Required "linux", "windows"
* `igroup_type` string "iscsi". Required
* `initiator` string. Required. Example: "iqn.1998-01.com.vmware:t1esx152-132-431b8380"

### Example ###

````ruby
#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

````


netapp_lun
------------
SVM-management of lun creation. Creating the igroup, and volume are pre-requisites necesarry for creation.

### Actions ###
This resource has the following actions:

* `:create` Default.
* `:map` map the lun created if the igroup is created

### Attributes ###
This resource has the following attributes:

* `name` string, name attribute. Volume name. Required.
* `svm` string. Name of managed SVM. Required
* `size` string. Required "50g"
* `path` string Path of the SVM volume and lun. Required
* `igroup` string. Required.
* `id` string the id where the lun is created. Required.


### Example ###

````ruby
lpath = "/vol/"+vol[:name]+"/"+lun[:name]
netapp_lun lpath do
svm node['netapp']['vserver']
igroup "iscsi_#{node['hostname']}_#{node['ipaddress']}"
id lun['id'].to_s

action :nothing
end

netapp_lun lun do
svm node['netapp']['vserver']
path lpath
size ((lun['lsize']*1024**3).to_i).to_s
ostype vol['ostype']
comment node['volume']['comment']
allocation node['lun']['allocation']
reservation node['lun']['reservation']
action :create
notifies :map, "netapp_lun[#{lpath}]", :immediately
end

````


Contributing
Expand Down
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" || result.results_errno == "9012"
elsif result.results_errno == "17" || result.results_errno == "9012" || 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"
#If the resource already exists, then ignore the error and proceed with the next resource.
#Do not update resource count.
return false
Expand Down
58 changes: 29 additions & 29 deletions providers/igroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
# Provider:: igroup
#

include NetApp::Api
include NetApp::Api

use_inline_resources
use_inline_resources

action :create do
action :create do

# Create API Request.
netapp_igroup_api = netapp_hash
# 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
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
# Invoke NetApp API.
resource_update = invoke(netapp_igroup_api)
new_resource.updated_by_last_action(true) if resource_update

end
end

action :add_rule do
action :add_rule do

# Create API Request.
netapp_igroup_add_api = netapp_hash
# 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
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
# Invoke NetApp API.
resource_update = invoke(netapp_igroup_add_api)
new_resource.updated_by_last_action(true) if resource_update

end
end
21 changes: 21 additions & 0 deletions providers/lun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@
new_resource.updated_by_last_action(true) if resource_update

end


action :map do

# Create API Request.
netapp_lun_map_api = netapp_hash

netapp_lun_map_api[:api_name] = "lun-map"
netapp_lun_map_api[:resource] = "lun"
netapp_lun_map_api[:action] = "map"
netapp_lun_map_api[:svm] = new_resource.svm
#netapp_lun_map_api[:api_attribute]["lun"] = new_resource.name
netapp_lun_map_api[:api_attribute]["path"] = new_resource.name
netapp_lun_map_api[:api_attribute]["initiator-group"] = new_resource.igroup
netapp_lun_map_api[:api_attribute]["lun-id"] = new_resource.id

# Invoke NetApp API.
resource_update = invoke(netapp_lun_map_api)
new_resource.updated_by_last_action(true) if resource_update

end
3 changes: 3 additions & 0 deletions recipes/igroup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Cookbook Name:: netapp
# Recipe:: igroup

#Igroup create
netapp_igroup node['igroup']['name'] do
svm node['netapp']['vserver']
Expand Down
16 changes: 8 additions & 8 deletions recipes/lun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


#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
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
21 changes: 10 additions & 11 deletions resources/igroup.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#
# Author:: Cesar Felce (<[email protected]>)
# Cookbook Name:: netapp
# Resource:: igroup
# Author:: Cesar Felce (<[email protected]>)
# Cookbook Name:: netapp
# Resource:: igroup
#

actions :create, :add_rule
default_action :create
actions :create, :add_rule
default_action :create

attribute :name, :kind_of => String, :required => true, :name_attribute => true
attribute :svm, :kind_of => String
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 :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
attribute :initiator, :kind_of => String, :required => true
53 changes: 26 additions & 27 deletions resources/lun.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
# Author:: Cesar Felce (<[email protected]>)
# Cookbook Name:: netapp
# Resource:: lun
#
# Author:: Cesar Felce (<[email protected]>)
# Cookbook Name:: netapp
# Resource:: lun
# Copyright:: 2014, Chef Software, Inc <[email protected]>
#
# 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
#
# 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
#
# 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.
# 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
actions :create
default_action :create

attribute :name, :kind_of => String, :required => true, :name_attribute => true
attribute :svm, :kind_of => String
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 :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
attribute :igroup, :kind_of => String, :required => true
attribute :id, :kind_of => String, :required => true
20 changes: 12 additions & 8 deletions spec/helpers/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ def delete_netapp_volume(resource_name)
ChefSpec::Matchers::ResourceMatcher.new('netapp_volume', :delete, resource_name)
end

def create_netapp_lun(resource_name)
ChefSpec::Matchers::ResourceMatcher.new('netapp_lun', :create, resource_name)
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)
def map_netapp_lun(resource_name)
ChefSpec::Matchers::ResourceMatcher.new('netapp_lun', :map, resource_name)
end

def add_rule_netapp_igroup(resource_name)
ChefSpec::Matchers::ResourceMatcher.new('netapp_igroup', :add_rule, 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

0 comments on commit 617f42e

Please sign in to comment.