knife-sce 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
1
+ #
2
+ # Author:: Rad Gruchalski (<radek@gruchalski.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceStorageOfferings < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce storage offerings (options)"
27
+
28
+ option :datacenter,
29
+ :short => "-Z LOCATION_ID",
30
+ :long => "--data-center LOCATION_ID",
31
+ :description => "Data center location ID, use knife sce location list to learn more about possible locations."
32
+
33
+ def run
34
+
35
+ $stdout.sync = true
36
+
37
+ validate!
38
+
39
+ offer_list = [
40
+ ui.color('Offering ID', :bold),
41
+ ui.color("Name", :bold),
42
+ ui.color("Label", :bold),
43
+ ui.color("Location", :bold),
44
+ ui.color('Supported sizes', :bold),
45
+ ui.color('Supported formats', :bold),
46
+ ui.color('Price', :bold)
47
+ ].flatten.compact
48
+
49
+ output_column_count = offer_list.length
50
+
51
+ connection_storage.offerings.all.each do |offer|
52
+
53
+ formats = []
54
+ offer.supported_formats.each do |format|
55
+ formats << format["id"]
56
+ end
57
+ sizes = offer.supported_sizes.split(",")
58
+
59
+ did = datacenter_id
60
+ if did.nil? or did.eql?( offer.location )
61
+
62
+ offer_list << offer.id.to_s
63
+ offer_list << offer.name.to_s
64
+ offer_list << offer.label.to_s
65
+ offer_list << connection.locations.get(offer.location).name
66
+ offer_list << "#{sizes[0].to_s}GB"
67
+ offer_list << formats.join(", ")
68
+ offer_list << "#{offer.price['rate']}#{offer.price['currencyCode']}/#{offer.price['pricePerQuantity']}#{offer.price['unitOfMeasure']}"
69
+
70
+ (1...sizes.length).each do |index|
71
+ offer_list << " "
72
+ offer_list << " "
73
+ offer_list << " "
74
+ offer_list << " "
75
+ offer_list << "#{sizes[index].to_s}GB"
76
+ offer_list << " "
77
+ offer_list << " "
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ puts "\n"
85
+ puts ui.list(offer_list, :uneven_columns_across, output_column_count)
86
+
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: John E. Vincent (<lusis.org+github.com@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceVlanList < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce vlan list"
27
+
28
+ def run!
29
+ connection.vlans.all
30
+ end
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ vlan_list = [
38
+ ui.color('Name', :bold),
39
+ ui.color('VLAN ID', :bold),
40
+ ui.color("Location", :bold)
41
+ ].flatten.compact
42
+
43
+ output_column_count = vlan_list.length
44
+
45
+ vlans = run!
46
+
47
+ vlans.each do |vlan|
48
+ vlan_list << vlan.name.to_s
49
+ vlan_list << vlan.id.to_s
50
+ vlan_list << connection.locations.get(vlan.location).name.to_s
51
+ end
52
+
53
+ puts ui.list(vlan_list, :uneven_columns_across, output_column_count)
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Rad Gruchalski (<radek@gruchalski.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceVolumeAttach < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce volume attach INSTANCE_ID VOLUME [VOLUME]"
27
+
28
+ def run
29
+
30
+ $stdout.sync = true
31
+
32
+ validate!
33
+
34
+ (1..@name_args.length-1).each do |idx|
35
+ puts "Attaching volume #{@name_args[idx]} to #{name_args[0]}"
36
+ begin
37
+ res = connection.modify_instance(@name_args[0], {
38
+ "type" => "attach",
39
+ "storageID" => @name_args[idx]
40
+ })
41
+ rescue Exception => e
42
+ ui.error("There was an error while attaching volume #{@name_args[idx]}. Error is #{e.to_s}")
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,126 @@
1
+ #
2
+ # Author:: Rad Gruchalski (<radek@gruchalski.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceVolumeCreate < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce volume create (options)"
27
+
28
+ option :name,
29
+ :short => "-N NAME",
30
+ :long => "--name NAME",
31
+ :description => "Name of the volume to create."
32
+
33
+ option :datacenter,
34
+ :short => "-Z LOCATION_ID",
35
+ :long => "--data-center LOCATION_ID",
36
+ :description => "Data center location ID, use knife sce location list to learn more about possible locations.",
37
+ :proc => Proc.new { |key| Chef::Config[:knife][:sce_location_id] = key }
38
+
39
+ option :offering_id,
40
+ :short => "-O OFFER_ID",
41
+ :long => "--offering-id OFFER_ID",
42
+ :description => "..."
43
+
44
+ option :size,
45
+ :short => "-S SIZE",
46
+ :long => "--size SIZE",
47
+ :description => "Size "
48
+
49
+ option :format,
50
+ :short => "-F FORMAT",
51
+ :long => "--format FORMAT",
52
+ :description => "...",
53
+ :default => "ext3"
54
+
55
+ def run
56
+
57
+ $stdout.sync = true
58
+
59
+ Fog.timeout = Chef::Config[:knife][:sce_max_timeout] || 6000
60
+
61
+ validate!
62
+
63
+ disk_launch_desc = {
64
+ :name => config[:name],
65
+ :offering_id => config[:offering_id],
66
+ :format => config[:format].upcase,
67
+ :location_id => datacenter_id,
68
+ :size => config[:size]
69
+ }
70
+
71
+ puts "Creating volume #{config[:name]}"
72
+
73
+ volume = connection_storage.volumes.create(disk_launch_desc)
74
+
75
+ puts "Volume #{config[:name]} created, volume ID is #{volume.id}. Waiting for ready..."
76
+
77
+ volume.wait_for { ready? }
78
+
79
+ puts "Volume #{config[:name]} ready to use."
80
+
81
+ puts "\n"
82
+
83
+ volume.id.to_s
84
+ msg_pair("Volume ID", volume.id.to_s )
85
+ msg_pair("Name", volume.name.to_s )
86
+ msg_pair("State", volume.state.to_s )
87
+ msg_pair("Size", volume.size.to_s )
88
+ msg_pair("Location", connection.locations.get(volume.location_id).name )
89
+ msg_pair("Format", volume.format.to_s )
90
+ msg_pair("Offering ID", volume.offering_id.to_s )
91
+ msg_pair("Owner", volume.owner.to_s )
92
+
93
+ end
94
+
95
+ def validate!
96
+
97
+ super([:ibm_username, :ibm_password, :size, :format, :offering_id, :datacenter, :name])
98
+
99
+ @offering = connection_storage.offerings.get( config[:offering_id] )
100
+
101
+ if @offering.nil?
102
+ ui.error("Storage offering #{config[:offering_id]} does not exist.")
103
+ exit 1
104
+ else
105
+
106
+ formats = []
107
+ @offering.supported_formats.each do |format|
108
+ formats << format["id"]
109
+ end
110
+ sizes = @offering.supported_sizes.split(",")
111
+
112
+ if !formats.include?( config[:format].upcase )
113
+ ui.error("Format #{config[:format].upcase} not supported.")
114
+ exit 1
115
+ end
116
+ if !sizes.include?( config[:size] )
117
+ ui.error("Format #{config[:size]} not supported.")
118
+ exit 1
119
+ end
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Rad Gruchalski (<radek@gruchalski.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceVolumeDelete < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce volume delete VOLUME [VOLUME]"
27
+
28
+ def run
29
+
30
+ $stdout.sync = true
31
+
32
+ validate!
33
+
34
+ @name_args.each do |v|
35
+ connection_storage.volumes.all.each do |volume|
36
+ if volume.id.eql?( v ) || volume.name.eql?( v )
37
+ ui.confirm "Are you sure you want to delete volume #{volume.name}"
38
+ begin
39
+ volume.destroy
40
+ puts "Delete request for volume #{volume.name} issued."
41
+ rescue Exception => e
42
+ ui.error("There was an error while issuing a delete request for volume #{@name_args[idx]}. Error is #{e.to_s}")
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,50 @@
1
+ #
2
+ # Author:: Rad Gruchalski (<radek@gruchalski.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceVolumeDetach < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce volume detach INSTANCE_ID VOLUME [VOLUME]"
27
+
28
+ def run
29
+
30
+ $stdout.sync = true
31
+
32
+ validate!
33
+
34
+ (1..@name_args.length-1).each do |idx|
35
+ puts "Detaching volume #{@name_args[idx]} from #{name_args[0]}"
36
+ begin
37
+ res = connection.modify_instance(@name_args[0], {
38
+ "type" => "detach",
39
+ "storageID" => @name_args[idx]
40
+ })
41
+ puts "Detach request for volume #{@name_args[idx]} issued."
42
+ rescue Exception => e
43
+ ui.error("There was an error while detaching volume #{@name_args[idx]}. Error is #{e.to_s}")
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Author:: Rad Gruchalski (<radek@gruchalski.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife/sce_base'
19
+
20
+ class Chef
21
+ class Knife
22
+ class SceVolumeList < Knife
23
+
24
+ include Knife::SceBase
25
+
26
+ banner "knife sce volume list (options)"
27
+
28
+ option :name,
29
+ :short => "-n",
30
+ :long => "--no-name",
31
+ :boolean => true,
32
+ :default => true,
33
+ :description => "Do not display name tag in output"
34
+
35
+ option :owner,
36
+ :short => "-o",
37
+ :long => "--no-owner",
38
+ :boolean => true,
39
+ :default => true,
40
+ :description => "Do not display owner in output"
41
+
42
+ def run!
43
+ connection_storage.volumes.all
44
+ end
45
+
46
+ def run
47
+ $stdout.sync = true
48
+
49
+ validate!
50
+
51
+ disk_list = [
52
+ ui.color('Volume ID', :bold),
53
+ ui.color("Instance ID", :bold),
54
+ ui.color("Name", :bold),
55
+ ui.color('State', :bold),
56
+ ui.color('Size (GB)', :bold),
57
+ ui.color('Location', :bold),
58
+ ui.color('Format', :bold),
59
+ ui.color('Offering', :bold),
60
+ ui.color('Owner', :bold)
61
+
62
+ ].flatten.compact
63
+
64
+ output_column_count = disk_list.length
65
+
66
+ volumes = run!
67
+
68
+ volumes.each do |volume|
69
+ disk_list << volume.id.to_s
70
+ disk_list << volume.instance_id.to_s
71
+ disk_list << volume.name.to_s
72
+ disk_list << volume.state.to_s
73
+ disk_list << volume.size.to_s
74
+ disk_list << connection.locations.get(volume.location_id).name
75
+ disk_list << volume.format.to_s
76
+ disk_list << volume.offering_id.to_s
77
+ disk_list << volume.owner.to_s
78
+ end
79
+
80
+ puts ui.list(disk_list, :uneven_columns_across, output_column_count)
81
+
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module SCE
3
+ VERSION = "0.2.0"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-sce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rad Gruchalski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fog
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.14.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.14.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: chef
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.10.10
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.10.10
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-core
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-expectations
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-mocks
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec_junit_formatter
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: IBM SCE tools for Chef's knife
111
+ email:
112
+ - radek@gruchalski.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - README.rdoc
117
+ - LICENSE
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - LICENSE
122
+ - README.rdoc
123
+ - knife-sce.gemspec
124
+ - lib/chef/knife/sce_address_create.rb
125
+ - lib/chef/knife/sce_address_delete.rb
126
+ - lib/chef/knife/sce_address_list.rb
127
+ - lib/chef/knife/sce_address_offerings.rb
128
+ - lib/chef/knife/sce_base.rb
129
+ - lib/chef/knife/sce_image_describe.rb
130
+ - lib/chef/knife/sce_instance_data.rb
131
+ - lib/chef/knife/sce_key_create.rb
132
+ - lib/chef/knife/sce_key_delete.rb
133
+ - lib/chef/knife/sce_key_get.rb
134
+ - lib/chef/knife/sce_key_list.rb
135
+ - lib/chef/knife/sce_location_list.rb
136
+ - lib/chef/knife/sce_server_create.rb
137
+ - lib/chef/knife/sce_server_delete.rb
138
+ - lib/chef/knife/sce_server_list.rb
139
+ - lib/chef/knife/sce_storage_offerings.rb
140
+ - lib/chef/knife/sce_vlan_list.rb
141
+ - lib/chef/knife/sce_volume_attach.rb
142
+ - lib/chef/knife/sce_volume_create.rb
143
+ - lib/chef/knife/sce_volume_delete.rb
144
+ - lib/chef/knife/sce_volume_detach.rb
145
+ - lib/chef/knife/sce_volume_list.rb
146
+ - lib/knife-sce/version.rb
147
+ homepage:
148
+ licenses: []
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.25
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: IBM SCE tools for Chef's knife
171
+ test_files: []