three-par 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b56abc21cf5652b125de2ca687eac33db52b617
4
+ data.tar.gz: 4e1758b742fcf10a301660ccc25104089334416e
5
+ SHA512:
6
+ metadata.gz: 99f2bae2b64fcf0434d7ef66cf99ef46a775c2f02e18e787206709c25e8235731bead0201f5b291a1e95a6a814dd8d93735cbef681b2788794ab369238150ad4
7
+ data.tar.gz: 03aeb1fc1fefeb39de7527258012f0946942123d911d7466abf493179e97cc8af6251813b2bbac751ac5885681af56ddd64e212c05811089c81f5ef93c74a827
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at TODO: Write your email address. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in three-par.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # Three::Par
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/three/par`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'three-par'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install three-par
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/three-par. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "three/par"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,140 @@
1
+ require "three/par/version"
2
+ require 'rest-client'
3
+ require 'yaml'
4
+ module Three
5
+ module Par
6
+ # Your code goes here...
7
+ def retrieve_3par_session_key(node)
8
+ options = {:content_type => 'application/json',:accept => 'application/json'}
9
+ credentials = {:user => node["username"], :password => node["password"]}.to_json
10
+ post = RestClient.post("http://#{node['ip']}:8008/api/v1/credentials", credentials, options)
11
+ JSON.parse(post)["key"]
12
+ end
13
+
14
+ def rest_call(type, node, path, session_key, payload=nil)
15
+ url = URI.escape("http://#{node['ip']}:8008" + path)
16
+ headers = {
17
+ :content_type => 'application/json',
18
+ :accept => 'application/json',
19
+ 'X-HP3PAR-WSAPI-SessionKey' => "#{session_key}",}
20
+ begin
21
+ response = RestClient::Request.execute(:method => type, :url => url, :payload => payload, :headers => headers)
22
+ rescue RestClient::Forbidden => error
23
+ binding.pry
24
+ raise JSON.parse(error.response)["desc"]
25
+ rescue RestClient::BadRequest => error
26
+ binding.pry
27
+ raise JSON.parse(error.response)["desc"]
28
+ rescue RestClient::Conflict => error
29
+ binding.pry
30
+ raise JSON.parse(error.response)["desc"]
31
+ end
32
+ JSON.parse(response) rescue ''
33
+ end
34
+
35
+ def delete_session_key(node, session_key)
36
+ RestClient.delete("http://#{node['ip']}:8008/api/v1/credentials/#{session_key}",{:content_type => 'application/json',:accept => 'application/json'})
37
+ end
38
+
39
+ def display_cpgs(node,cpg_file, session_key)
40
+ response = rest_call(:get, node, '/api/v1/cpgs', session_key)
41
+ File.open("#{Chef::Config[:file_cache_path]}/#{cpg_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
42
+ end
43
+
44
+ def display_hosts(node, host_file, session_key)
45
+ response = rest_call(:get, node, '/api/v1/hosts', session_key)
46
+ File.open("#{Chef::Config[:file_cache_path]}/#{host_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
47
+ end
48
+
49
+ def display_vluns(node, host_file, session_key)
50
+ response = rest_call(:get, node, '/api/v1/vluns', session_key)
51
+ File.open("#{Chef::Config[:file_cache_path]}/#{host_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
52
+ end
53
+
54
+ def display_volumes(node, volume_file, session_key)
55
+ response = rest_call(:get, node, '/api/v1/volumes', session_key)
56
+ File.open("#{Chef::Config[:file_cache_path]}/#{volume_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
57
+ end
58
+
59
+ def display_capacity(node, capacity_file, session_key)
60
+ response = rest_call(:get, node, '/api/v1/capacity', session_key)
61
+ File.open("#{Chef::Config[:file_cache_path]}/#{capacity_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
62
+ end
63
+
64
+ def display_users(node, users_file, session_key)
65
+ response = rest_call(:get, node, '/api/v1/users', session_key)
66
+ File.open("#{Chef::Config[:file_cache_path]}/#{users_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
67
+ end
68
+
69
+ def display_roles(node, roles_file, session_key)
70
+ response = rest_call(:get, node, '/api/v1/roles', session_key)
71
+ File.open("#{Chef::Config[:file_cache_path]}/#{roles_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
72
+ end
73
+
74
+ def delete_cpg(node, cpg_name, session_key)
75
+ rest_call(:delete, node, "/api/v1/cpgs/#{cpg_name}", session_key)
76
+ end
77
+
78
+ def delete_host(node, host_name, session_key)
79
+ rest_call(:delete, node, "/api/v1/hosts/#{host_name}", session_key)
80
+ end
81
+
82
+ def show_cpg(node, cpg_name, cpg_file, session_key)
83
+ response = rest_call(:get, node, "/api/v1/cpgs/#{cpg_name}", session_key)
84
+ File.open("#{Chef::Config[:file_cache_path]}/#{cpg_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
85
+ end
86
+
87
+ def create_cpg(node, session_key, payload)
88
+ rest_call(:post, node, "/api/v1/cpgs", session_key, payload.to_json)
89
+ end
90
+
91
+ def create_host(node,session_key,payload)
92
+ rest_call(:post, node, "/api/v1/hosts", session_key, payload.to_json)
93
+ end
94
+
95
+ def modify_cpg(node, cpg_name, new_cpg_name, session_key, payload)
96
+ rest_call(:put, node, "/api/v1/cpgs/#{cpg_name}", session_key, payload.to_json)
97
+ end
98
+
99
+ def create_volume(node, session_key, payload)
100
+ rest_call(:post, node, "/api/v1/volumes/", session_key, payload.to_json)
101
+ end
102
+
103
+ def show_volume(node, volume_name, volume_file, session_key)
104
+ response = rest_call(:get, node, "/api/v1/volumes/#{volume_name}", session_key)
105
+ File.open("#{Chef::Config[:file_cache_path]}/#{volume_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
106
+ end
107
+
108
+ def grow_volume(node, volume, size, session_key)
109
+ payload = {
110
+ "action" => 3,
111
+ "sizeMiB" => size
112
+ }
113
+ rest_call(:put, node, "/api/v1/volumes/#{volume}", session_key, payload.to_json)
114
+ end
115
+
116
+ def delete_volume(node, volume, session_key)
117
+ rest_call(:delete, node, "/api/v1/volumes/#{volume}", session_key)
118
+ end
119
+
120
+ def create_vlun(node, session_key, payload)
121
+ rest_call(:post, node, "/api/v1/vluns", session_key, payload.to_json)
122
+ end
123
+
124
+ def show_user(node, user_name, user_file, session_key)
125
+ response = rest_call(:get, node, "/api/v1/users/#{user_name}", session_key)
126
+ File.open("#{Chef::Config[:file_cache_path]}/#{user_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
127
+ end
128
+
129
+ def show_role(node, role_name, role_file, session_key)
130
+ response = rest_call(:get, node, "/api/v1/roles/#{role_name}", session_key)
131
+ File.open("#{Chef::Config[:file_cache_path]}/#{role_file}.txt", 'a+') { |file| file.write(response.to_yaml) }
132
+ end
133
+
134
+ def remove_vlun(node, volume_name, lun, host_name, session_key)
135
+ payload = volume_name + "," + lun.to_s + "," + host_name
136
+ path = URI.escape("/api/v1/vluns/" + payload)
137
+ rest_call(:delete, node, path , session_key)
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,5 @@
1
+ module Three
2
+ module Par
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'three/par/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "three-par"
8
+ spec.version = Three::Par::VERSION
9
+ spec.authors = ["Anirudh Gupta"]
10
+ spec.email = ["anirudhg47@gmail.com"]
11
+
12
+ spec.summary = %q{Leverages 3par API's to perform administrative tasks on 3par.}
13
+
14
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
15
+ # delete this section to allow pushing this gem to any host.
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
+ end
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.11"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rest-client"
30
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: three-par
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anirudh Gupta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - anirudhg47@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/three/par.rb
70
+ - lib/three/par/version.rb
71
+ - three-par.gemspec
72
+ homepage:
73
+ licenses: []
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Leverages 3par API's to perform administrative tasks on 3par.
96
+ test_files: []