ocp 0.0.17 → 0.0.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea86e5351cf24e1f9b223cc420f4b20e42cc268a
4
- data.tar.gz: aa5efac06c58092aedd49a339b4ddd15b641b62d
3
+ metadata.gz: 6c7d7f072f9742b4e234ed7399dce39ecef5ea54
4
+ data.tar.gz: 32ab8a19007008cd27f0b2e8cc179d573576a69d
5
5
  SHA512:
6
- metadata.gz: f821202450fdfa8eb69c8d9a3788e7905d6b40716b39266f2647f18fc5556a6f78f3714d8591c1d559076ac2554f3a7a4431ca5574c664480277db97f2f34d4a
7
- data.tar.gz: e1576b184ae89972c5cf67cb9d0269b11c886c1698239022b1939c59350b92ab8caddbe37a50cdd3d49ea7b4b2ccaebd1a6add8c6eea4b99bb331774a2d9a5e6
6
+ metadata.gz: 55d38b7791b115ae97df28fa77eadb527132921d34b289e31041224b40581c638ce498d4ad21d93e14a8b9027b499a0eb4ef8aaac938000161bb955e308395d7
7
+ data.tar.gz: 83dfa68cde32b13313aa523fd19494f72b433f9bd95b9b5c0a70ad6a8346f1d7758e959b5d3183b3fd03fc0a9d344f9c2135f1f14b66dc1e416ace14ad4e6302
@@ -44,8 +44,12 @@ class Base
44
44
 
45
45
  end
46
46
 
47
- def setup(ocpconfig)
48
- @client.setup(ocpconfig)
47
+ def setup(url, noverifyssl, pretty, debug , token=nil, clientcertfile=nil, clientkeyfile=nil, clientcafile=nil)
48
+ @client.setup(url, noverifyssl, pretty, debug , token, clientcertfile, clientkeyfile, clientcafile)
49
+ end
50
+
51
+ def setup_by_config_file(configfile, pretty=nil, debug=nil)
52
+ @client.setup_by_config_file(configfile, pretty, debug)
49
53
  end
50
54
 
51
55
  def list
@@ -24,8 +24,8 @@ load 'base/v1/V1.rb'
24
24
 
25
25
  class Api < V1
26
26
 
27
- def initialize(name=nil)
28
- super(name, "api")
27
+ def initialize(path=nil, namespace=nil)
28
+ super("api", path, namespace)
29
29
  end
30
30
 
31
31
  def showapi
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ #####################################################################################
3
+ # Copyright 2016 Kenneth Evensen <kenneth.evensen@redhat.com>
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
+ #
19
+ # Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
20
+ #
21
+ #####################################################################################
22
+
23
+ require 'json'
24
+
25
+ class ObjectMeta
26
+
27
+ attr_accessor :name
28
+ attr_accessor :namespace
29
+ attr_accessor :selflink
30
+
31
+ def initialize
32
+ @name = nil
33
+ @namespace = nil
34
+ @selflink = nil
35
+ end
36
+
37
+ def get_hash
38
+ metaHash = Hash.new
39
+ unless @name.nil?
40
+ metaHash[:name] = @name
41
+ end
42
+
43
+ unless @namespace.nil?
44
+ metaHash[:namespace] = @namespace
45
+ end
46
+
47
+ unless @selflink.nil?
48
+ metaHash[:selflink] = @selflink
49
+ end
50
+
51
+ return metaHash
52
+ end
53
+
54
+ def get_json
55
+ return JSON.generate(get_hash)
56
+ end
57
+ end
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ #####################################################################################
3
+ # Copyright 2015 Kenneth Evensen <kenneth.evensen@redhat.com>
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
+ #
19
+ # Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
20
+ #
21
+ #####################################################################################
22
+ load 'base/v1/api/Api.rb'
23
+ load 'base/v1/api/ResourceQuotaSpec.rb'
24
+ load 'base/v1/api/ObjectMeta.rb'
25
+
26
+ require 'json'
27
+
28
+ class ResourceQuota < Api
29
+
30
+ def initialize(namespace=nil)
31
+ super("resourcequotas", namespace)
32
+ @namespace = namespace
33
+ end
34
+
35
+ def list_resource_quotas
36
+ return list
37
+ end
38
+
39
+ def create_resource_quota(name, pods=nil, replicationcontrollers=nil, services=nil,
40
+ configmaps=nil, persistentvolumeclaims=nil,
41
+ resourcequotas=nil)
42
+
43
+ rqspec = ResourceQuotaSpec.new
44
+
45
+ rqspec.pods = pods
46
+ rqspec.replicationcontrollers = replicationcontrollers
47
+ rqspec.services = services
48
+ rqspec.configmaps = configmaps
49
+ rqspec.persistentvolumeclaims = persistentvolumeclaims
50
+ rqspec.resourcequotas = resourcequotas
51
+
52
+ objectmeta = ObjectMeta.new
53
+ objectmeta.name = name
54
+ objectmeta.namespace = @namespace
55
+
56
+ body = {'spec' => rqspec.get_hash, 'metadata' => objectmeta.get_hash}
57
+ data = create(body)
58
+ return data
59
+
60
+ end
61
+
62
+ def delete_resource_quota(name)
63
+ data = delete(name)
64
+ return data
65
+ end
66
+
67
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ #####################################################################################
3
+ # Copyright 2015 Kenneth Evensen <kenneth.evensen@redhat.com>
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
+ #
19
+ # Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
20
+ #
21
+ #####################################################################################
22
+
23
+ class ResourceQuotaSpec
24
+
25
+ attr_accessor :pods
26
+ attr_accessor :replicationcontrollers
27
+ attr_accessor :resourcequotas
28
+ attr_accessor :services
29
+ attr_accessor :secrets
30
+ attr_accessor :configmaps
31
+ attr_accessor :persistentvolumeclaims
32
+
33
+ def initialize
34
+ @pods = nil
35
+ @replicationcontrollers = nil
36
+ @resourcequotas = nil
37
+ @services = nil
38
+ @secrets = nil
39
+ @configmaps = nil
40
+ @persistentvolumeclaims = nil
41
+ end
42
+
43
+ def get_hash
44
+ quota_hash = Hash.new
45
+ unless @pods.nil?
46
+ quota_hash[:pods] = @pods
47
+ end
48
+
49
+ unless @replicationcontrollers.nil?
50
+ quota_hash[:replicationcontrollers] = @replicationcontrollers
51
+ end
52
+
53
+ unless @services.nil?
54
+ quota_hash[:services] = @services
55
+ end
56
+
57
+ unless @configmaps.nil?
58
+ quota_hash[:configmaps] = @configmaps
59
+ end
60
+
61
+ unless @persistentvolumeclaims.nil?
62
+ quota_hash[:persistentvolumeclaims] = @persistentvolumeclaims
63
+ end
64
+
65
+ unless @resourcequotas.nil?
66
+ quota_hash[:resourcequotas] = @resourcequotas
67
+ end
68
+
69
+ hard_hash = {'hard' => quota_hash}
70
+ return hard_hash
71
+
72
+ end
73
+
74
+ end
@@ -20,8 +20,6 @@
20
20
  #
21
21
  #####################################################################################
22
22
 
23
- require 'json'
24
-
25
23
  load 'base/v1/V1.rb'
26
24
 
27
25
  class OcpApi < V1
@@ -21,6 +21,7 @@
21
21
  #####################################################################################
22
22
 
23
23
  load 'base/v1/ocpapi/ObjectMeta.rb'
24
+ require 'json'
24
25
 
25
26
  class Project < OcpApi
26
27
 
@@ -34,6 +35,20 @@ class Project < OcpApi
34
35
  return data
35
36
  end
36
37
 
38
+ def exists?(project_name)
39
+ project_list = listprojects
40
+ data = JSON.parse project_list
41
+ list = data['items']
42
+ list.each do |key|
43
+ if project_name == key['metadata']['name']
44
+ return true
45
+ end
46
+ end
47
+
48
+ return false
49
+
50
+ end
51
+
37
52
  def deleteproject(name)
38
53
  data = nil
39
54
  data = delete(name)
@@ -44,18 +44,65 @@ class OcpClient
44
44
  @response = nil
45
45
  end
46
46
 
47
- def setup(ocpconfig)
48
- @noverifyssl = ocpconfig.noverifyssl
49
- @url = ocpconfig.master
50
- @pretty = ocpconfig.pretty
51
- @debug = ocpconfig.debug
52
- @token = ocpconfig.token
53
- @clientcert = ocpconfig.clientcert
54
- @clientkey = ocpconfig.clientkey
55
- @clientca = ocpconfig.clientca
56
- @clientcafile = ocpconfig.clientcafile
57
- return nil
58
- end
47
+ def setup(url, noverifyssl, pretty, debug, token,
48
+ clientcertfile, clientkeyfile, clientcafile)
49
+ @noverifyssl = noverifyssl
50
+ @pretty = pretty
51
+ @debug = debug
52
+
53
+ @url = url
54
+
55
+ unless clientcertfile.nil? or clientkeyfile.nil?
56
+ @clientcertfile = clientcertfile
57
+ @clientkeyfile = clientkeyfile
58
+ end
59
+
60
+ unless clientcafile.nil?
61
+ @clientcafile = clientcafile
62
+ end
63
+
64
+ unless @clientcertfile.nil? or @clientkeyfile.nil?
65
+ @clientcert = OpenSSL::X509::Certificate.new File.read @clientcertfile
66
+ @clientkey = OpenSSL::PKey::RSA.new File.read @clientkeyfile
67
+ end
68
+
69
+ unless @clientcafile.nil?
70
+ @clientca = OpenSSL::X509::Certificate.new File.read @clientcafile
71
+ end
72
+
73
+ unless token.nil?
74
+ @token = token
75
+ end
76
+
77
+ validate_options
78
+
79
+ end
80
+
81
+ def setup_by_config_file(configfile, pretty, debug)
82
+ config = read_config(configfile)
83
+ @debug=debug
84
+ @pretty=pretty
85
+
86
+ unless config.nil?
87
+ @token = config["connection"]["token"]
88
+ @url = config["connection"]["master"]
89
+ @noverifyssl = config["connection"]["no_verify_ssl"]
90
+ @clientcertfile = config["connection"]["client-certificate-file"]
91
+ @clientkeyfile = config["connection"]["client-key-file"]
92
+ @clientcafile = config["connection"]["client-ca-file"]
93
+ end
94
+
95
+ unless @clientcertfile.nil? or @clientkeyfile.nil?
96
+ @clientcert = OpenSSL::X509::Certificate.new File.read @clientcertfile
97
+ @clientkey = OpenSSL::PKey::RSA.new File.read @clientkeyfile
98
+ end
99
+
100
+ unless @clientcafile.nil?
101
+ @clientca = OpenSSL::X509::Certificate.new File.read @clientcafile
102
+ end
103
+
104
+ validate_options
105
+ end
59
106
 
60
107
 
61
108
  def get(location)
@@ -82,8 +129,14 @@ class OcpClient
82
129
 
83
130
  def call(location, body, method)
84
131
  if !@clientcert.nil? and !@clientkey.nil?
132
+ if @debug
133
+ puts "Calling by Certificate"
134
+ end
85
135
  return callbycert(location, body, method)
86
136
  else
137
+ if @debug
138
+ puts "Calling by Token"
139
+ end
87
140
  return callbytoken(location, body, method)
88
141
  end
89
142
  end
@@ -200,4 +253,26 @@ class OcpClient
200
253
  return "pretty=#{@pretty}"
201
254
  end
202
255
 
256
+ def validate_options
257
+
258
+ if @token.nil? and (@clientcertfile.nil? or @clientkeyfile.nil?)
259
+ raise MissingRequiredOptionException.new("token OR clientcertfile AND clientkeyfile")
260
+ elsif @url.nil?
261
+ raise MissingRequiredOptionException.new("master")
262
+ end
263
+ end
264
+
265
+ def read_config(configfile)
266
+ begin
267
+ unless configfile.nil?
268
+ return YAML.load_file(configfile)
269
+ else
270
+ return YAML.load_file("config.yaml")
271
+ end
272
+ rescue => exception
273
+ puts exception.message
274
+ puts "Unable to read config file #{configfile}. Proceeding"
275
+ end
276
+ end
277
+
203
278
  end
@@ -4,16 +4,16 @@ require 'commander'
4
4
 
5
5
 
6
6
  load 'exceptions/MissingRequiredOptionException.rb'
7
- load 'config/OcpConfig.rb'
8
-
9
7
  load 'base/v1/ocpapi/OcpApi.rb'
10
8
  load 'base/v1/ocpapi/OAuthClientAuthorization.rb'
11
9
  load 'base/v1/ocpapi/Policy.rb'
12
10
  load 'base/v1/ocpapi/ProjectRequest.rb'
11
+ load 'base/v1/ocpapi/Project.rb'
13
12
  load 'base/v1/ocpapi/Role.rb'
14
13
  load 'base/v1/ocpapi/RoleBinding.rb'
15
14
  load 'base/v1/ocpapi/Project.rb'
16
- load 'base/v1/api/Api.rb'
15
+ #load 'base/v1/api/Api.rb'
16
+ load 'base/v1/api/ResourceQuota.rb'
17
17
 
18
18
 
19
19
  class OcpCommander
@@ -41,14 +41,9 @@ class OcpCommander
41
41
  c.syntax = 'ocp getocpapi [options]'
42
42
  c.description = 'Retrieve the OpenShift Container Platform API'
43
43
  c.action do |args, options|
44
- # Do something or c.when_called Ocp::Commands::Getoapi,
45
- ocpconfig = OcpConfig.new
46
- ocpconfig.set_config_with_options(options)
47
- if ocpconfig.debug
48
- puts "Config: #{ocpconfig.inspect}"
49
- end
44
+
50
45
  ocpapi = OcpApi.new
51
- ocpapi.setup(ocpconfig)
46
+ ocpapi.setup_by_config_file(options.config)
52
47
  ocpapi.list
53
48
  puts "#{ocpapi.response}"
54
49
  end
@@ -60,17 +55,46 @@ class OcpCommander
60
55
  c.description = ''
61
56
  c.action do |args, options|
62
57
  # Do something or c.when_called Ocp::Commands::Getapi
63
- ocpconfig = OcpConfig.new
64
- ocpconfig.set_config_with_options(options)
65
- if ocpconfig.debug
66
- puts "Config: #{ocpconfig.inspect}"
67
- end
68
58
  api = Api.new
69
- api.setup(ocpconfig)
59
+ api.setup_by_config_file(options.config)
70
60
  puts "#{api.showapi}"
71
61
  end
72
62
  end
73
63
 
64
+ command :projectexists do |c|
65
+ c.syntax = 'ocp projectexists [options]'
66
+ c.summary = 'Check if a project exists'
67
+ c.description = 'Check if a project exists'
68
+ c.option '--name PROJECTNAME', String, 'The name for the project'
69
+ c.action do |args, options|
70
+ # Do something or c.when_called Ocp::Commands::Getapi
71
+ proj = Project.new
72
+ proj.setup_by_config_file(options.config, options.pretty, options.debug)
73
+
74
+ if proj.exists?(options.name)
75
+ puts "Project #{options.name} exists"
76
+ else
77
+ puts "Project #{options.name} doesn't exist"
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ command :listprojects do |c|
84
+ c.syntax = 'ocp projectexists [options]'
85
+ c.summary = 'Check if a project exists'
86
+ c.description = 'Check if a project exists'
87
+ c.option '--name PROJECTNAME', String, 'The name for the project'
88
+ c.action do |args, options|
89
+ # Do something or c.when_called Ocp::Commands::Getapi
90
+ proj = Project.new
91
+ proj.setup_by_config_file(options.config, options.pretty, options.debug)
92
+
93
+ puts "#{proj.listprojects}"
94
+
95
+ end
96
+ end
97
+
74
98
  command :createproject do |c|
75
99
  c.syntax = 'ocp createproject [options]'
76
100
  c.summary = 'Create a project request'
@@ -80,14 +104,8 @@ class OcpCommander
80
104
  c.option '--displayname [DISPLAYNAME]', String, 'The displayname for the project'
81
105
  c.action do |args, options|
82
106
  # Do something or c.when_called Ocp::Commands::Getapi
83
-
84
- ocpconfig = OcpConfig.new
85
- ocpconfig.set_config_with_options(options)
86
- if ocpconfig.debug
87
- puts "Config: #{ocpconfig.inspect}"
88
- end
89
107
  projreq = ProjectRequest.new
90
- projreq.setup(ocpconfig)
108
+ projreq.setup_by_config_file(options.config)
91
109
 
92
110
  data = projreq.createprojectrequest(options.name, options.description, options.displayname)
93
111
 
@@ -102,14 +120,8 @@ class OcpCommander
102
120
  c.option '--name PROJECTNAME', String, 'The name for the project'
103
121
  c.action do |args, options|
104
122
  # Do something or c.when_called Ocp::Commands::Getapi
105
-
106
- ocpconfig = OcpConfig.new
107
- ocpconfig.set_config_with_options(options)
108
- if ocpconfig.debug
109
- puts "Config: #{ocpconfig.inspect}"
110
- end
111
123
  project = Project.new
112
- project.setup(ocpconfig)
124
+ project.setup_by_config_file(options.config)
113
125
 
114
126
  data = project.deleteproject(options.name)
115
127
 
@@ -123,13 +135,8 @@ class OcpCommander
123
135
  c.option '--name PROJECTNAME', String, 'The name for the project'
124
136
  c.action do |args, options|
125
137
  # Do something or c.when_called Ocp::Commands::Getoapi,
126
- ocpconfig = OcpConfig.new
127
- ocpconfig.set_config_with_options(options)
128
- if ocpconfig.debug
129
- puts "Config: #{ocpconfig.inspect}"
130
- end
131
138
  policy = Policy.new
132
- policy.setup(ocpconfig)
139
+ policy.setup_by_config_file(options.config)
133
140
  puts "#{policy}"
134
141
  end
135
142
  end
@@ -139,13 +146,8 @@ class OcpCommander
139
146
  c.description = 'Retrieve the OAuthClientAuthorizations'
140
147
  c.action do |args, options|
141
148
  # Do something or c.when_called Ocp::Commands::Getoapi,
142
- ocpconfig = OcpConfig.new
143
- ocpconfig.set_config_with_options(options)
144
- if ocpconfig.debug
145
- puts "Config: #{ocpconfig.inspect}"
146
- end
147
149
  oauthpolicy = OAuthClientAuthorization.new
148
- oauthpolicy.setup(ocpconfig)
150
+ oauthpolicy.setup_by_config_file(options.config)
149
151
  puts "#{oauthpolicy}"
150
152
  end
151
153
  end
@@ -156,18 +158,13 @@ class OcpCommander
156
158
  c.option '--name [PROJECTNAME]', String, 'Optionally the name of the project'
157
159
  c.action do |args, options|
158
160
  # Do something or c.when_called Ocp::Commands::Getoapi,
159
- ocpconfig = OcpConfig.new
160
- ocpconfig.set_config_with_options(options)
161
- if ocpconfig.debug
162
- puts "Config: #{ocpconfig.inspect}"
163
- end
164
161
  roles = nil
165
162
  if options.name.nil?
166
163
  roles = Role.new
167
164
  else
168
165
  roles = Role.new(options.name)
169
166
  end
170
- roles.setup(ocpconfig)
167
+ roles.setup_by_config_file(options.config)
171
168
 
172
169
  puts "#{roles}"
173
170
  end
@@ -179,18 +176,13 @@ class OcpCommander
179
176
  c.option '--name [PROJECTNAME]', String, 'Optionally the name of the project'
180
177
  c.action do |args, options|
181
178
  # Do something or c.when_called Ocp::Commands::Getoapi,
182
- ocpconfig = OcpConfig.new
183
- ocpconfig.set_config_with_options(options)
184
- if ocpconfig.debug
185
- puts "Config: #{ocpconfig.inspect}"
186
- end
187
179
  roles = nil
188
180
  if options.name.nil?
189
181
  roles = RoleBinding.new
190
182
  else
191
183
  roles = RoleBinding.new(options.name)
192
184
  end
193
- roles.setup(ocpconfig)
185
+ roles.setup_by_config_file(options.config)
194
186
 
195
187
 
196
188
  puts "#{roles}"
@@ -205,15 +197,9 @@ class OcpCommander
205
197
  c.option '--role ROLE', String, 'The role to add to the user'
206
198
  c.action do |args, options|
207
199
  # Do something or c.when_called Ocp::Commands::Getoapi,
208
- ocpconfig = OcpConfig.new
209
- ocpconfig.set_config_with_options(options)
210
- if ocpconfig.debug
211
- puts "Config: #{ocpconfig.inspect}"
212
- end
213
-
214
200
  roles = RoleBinding.new(options.name)
215
201
 
216
- roles.setup(ocpconfig)
202
+ roles.setup_by_config_file(options.config)
217
203
  resp = roles.create_role_binding(options.user, options.role)
218
204
  puts "#{resp}"
219
205
 
@@ -227,22 +213,68 @@ class OcpCommander
227
213
  c.option '--user USERNAME', String, 'The name of the user'
228
214
  c.option '--role ROLE', String, 'The role to add to the user'
229
215
  c.action do |args, options|
230
- # Do something or c.when_called Ocp::Commands::Getoapi,
231
- ocpconfig = OcpConfig.new
232
- ocpconfig.set_config_with_options(options)
233
- if ocpconfig.debug
234
- puts "Config: #{ocpconfig.inspect}"
235
- end
236
216
 
237
217
  roles = RoleBinding.new(options.name)
238
218
 
239
- roles.setup(ocpconfig)
219
+ roles.setup_by_config_file(options.config)
240
220
  resp = roles.update_role_binding(options.user, options.role)
241
221
  puts "#{resp}"
242
222
 
243
223
  end
244
224
  end
245
225
 
226
+ command :list_resource_quotas do |c|
227
+ c.syntax = 'ocp list_resource_quotas [options]'
228
+ c.description = 'List a Project\'s Resource Quotas'
229
+ c.option '--name PROJECTNAME', String, 'The name of the project'
230
+ c.action do |args, options|
231
+ # Do something or c.when_called Ocp::Commands::Getoapi,
232
+ rq = ResourceQuota.new(options.name)
233
+
234
+ rq.setup_by_config_file(options.config)
235
+ resp = rq.list_resource_quotas
236
+ puts "#{resp}"
237
+
238
+ end
239
+ end
240
+
241
+ command :create_resource_quota do |c|
242
+ c.syntax = 'ocp create_resource_quota [options]'
243
+ c.description = 'Create a Project\'s Resource Quota'
244
+ c.option '--name PROJECTNAME', String, 'The name of the project'
245
+ c.option '--pods PODS', Integer, 'The number of pods'
246
+ c.option '--replicationcontrollers RCS', Integer, 'The number of replication controllers'
247
+ c.option '--services SERVICES', Integer, 'The number of services'
248
+ c.option '--configmaps CONFIGMAPS', Integer, 'The number of configmaps'
249
+ c.option '--persistentvolumeclaims PVCS', Integer, 'The number of persistent volume claims'
250
+ c.option '--resourcequotas RQS', Integer, 'The number of resource quotas'
251
+ c.action do |args, options|
252
+ rq = ResourceQuota.new(options.name)
253
+
254
+ rq.setup_by_config_file(options.config)
255
+ resp = rq.create_resource_quota(options.pods,
256
+ options.replicationcontrollers, options.services,
257
+ options.configmaps, options.persistentvolumeclaims, options.resourcequotas)
258
+ puts "#{resp}"
259
+ end
260
+ end
261
+ command :delete_resource_quota do |c|
262
+ c.syntax = 'ocp delete_resource_quota [options]'
263
+ c.description = 'Delete a Project\'s Resource Quota'
264
+ c.option '--name PROJECTNAME', String, 'The name of the project'
265
+ c.option '--quotaname QUOTANAME', String, 'The name of the quota object'
266
+ c.action do |args, options|
267
+ rq = ResourceQuota.new(options.name)
268
+
269
+ rq.setup_by_config_file(options.config)
270
+ resp = rq.delete_resource_quota(options.quotaname)
271
+ puts "#{resp}"
272
+
273
+ end
274
+ end
275
+
276
+
277
+
246
278
  run!
247
279
  end
248
280
 
data/lib/ocp.rb CHANGED
@@ -1,4 +1,3 @@
1
- load 'config/OcpConfig.rb'
2
1
  load 'commander/OcpCommander.rb'
3
2
  load 'base/v1/ocpapi/OcpApi.rb'
4
3
  load 'base/v1/api/Api.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Evensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -33,6 +33,9 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - lib/base/Base.rb
35
35
  - lib/base/v1/api/Api.rb
36
+ - lib/base/v1/api/ObjectMeta.rb
37
+ - lib/base/v1/api/ResourceQuota.rb
38
+ - lib/base/v1/api/ResourceQuotaSpec.rb
36
39
  - lib/base/v1/ocpapi/OAuthClientAuthorization.rb
37
40
  - lib/base/v1/ocpapi/ObjectMeta.rb
38
41
  - lib/base/v1/ocpapi/ObjectReference.rb
@@ -45,7 +48,6 @@ files:
45
48
  - lib/base/v1/V1.rb
46
49
  - lib/client/OcpClient.rb
47
50
  - lib/commander/OcpCommander.rb
48
- - lib/config/OcpConfig.rb
49
51
  - lib/exceptions/MissingRequiredOptionException.rb
50
52
  - lib/exceptions/NoObjectNameException.rb
51
53
  - lib/ocp.rb
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #####################################################################################
3
- # Copyright 2015 Kenneth Evensen <kenneth.evensen@redhat.com>
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
- #
19
- # Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
20
- #
21
- #####################################################################################
22
-
23
- require 'yaml'
24
- require 'openssl'
25
-
26
- class OcpConfig
27
- attr_reader :master
28
- attr_reader :token
29
- attr_reader :clientcertfile
30
- attr_reader :clientkeyfile
31
- attr_reader :clientcafile
32
- attr_reader :clientcert
33
- attr_reader :clientkey
34
- attr_reader :clientca
35
- attr_reader :noverifyssl
36
- attr_reader :output
37
- attr_reader :debug
38
- attr_reader :pretty
39
-
40
- def initialize
41
- @master = nil
42
- @token = nil
43
- @noverifyssl = false
44
- @output = :json
45
- @debug = false
46
- @pretty = false
47
- @clientcertfile = nil
48
- @clientkeyfile = nil
49
- @clientcafile = nil
50
- @clientcert = nil
51
- @clientkey = nil
52
- end
53
-
54
- def set_config_by_parameters(host, noverifyssl, pretty, debug , token=nil, clientcertfile=nil, clientkeyfile=nil, clientcafile=nil)
55
- @noverifyssl = noverifyssl
56
- @master = host
57
- @pretty = pretty
58
- @debug = debug
59
-
60
- unless clientcertfile.nil? or clientkeyfile.nil?
61
- @clientcertfile = clientcertfile
62
- @clientkeyfile = clientkeyfile
63
- end
64
-
65
- unless clientcafile.nil?
66
- @clientcafile = clientcafile
67
- end
68
-
69
- unless @clientcertfile.nil? or @clientkeyfile.nil?
70
- @clientcert = OpenSSL::X509::Certificate.new File.read @clientcertfile
71
- @clientkey = OpenSSL::PKey::RSA.new File.read @clientkeyfile
72
- end
73
-
74
- unless @clientcafile.nil?
75
- @clientca = OpenSSL::X509::Certificate.new File.read @clientcafile
76
- end
77
-
78
- unless token.nil?
79
- @token = token
80
- end
81
-
82
- validate_options
83
-
84
- end
85
-
86
- def set_config_with_options(options)
87
-
88
- unless options.configfile.nil?
89
- set_config_by_file(options.configfile)
90
- else
91
- set_config_by_file("config.yaml")
92
- end
93
- set_config_by_parameters(options.master, options.noverifyssl,
94
- options.pretty, options.debug, options.token,
95
- options.clientcertfile, options.clientkeyfile,
96
- options.clientcafile)
97
- end
98
-
99
-
100
-
101
- def set_config_by_file(configfile)
102
-
103
- config = read_config(configfile)
104
-
105
- unless config.nil?
106
- @token = config["connection"]["token"]
107
- @master = config["connection"]["master"]
108
- @noverifyssl = config["connection"]["no_verify_ssl"]
109
- @clientcertfile = config["connection"]["client-certificate-file"]
110
- @clientkeyfile = config["connection"]["client-key-file"]
111
- @clientcafile = config["connection"]["client-ca-file"]
112
- end
113
- #return nil
114
- end
115
-
116
- private
117
-
118
- def validate_options
119
-
120
- if @token.nil? and (@clientcertfile.nil? or @clientkeyfile.nil?)
121
- raise MissingRequiredOptionException.new("token OR clientcertfile AND clientkeyfile")
122
- elsif @master.nil?
123
- raise MissingRequiredOptionException.new("master")
124
- end
125
- end
126
-
127
- def read_config(configfile)
128
- begin
129
- unless configfile.nil?
130
- return YAML.load_file(configfile)
131
- else
132
- return YAML.load_file("config.yaml")
133
- end
134
- rescue => exception
135
- puts exception.message
136
- puts "Unable to read config file #{configfile}. Proceeding"
137
- end
138
- end
139
-
140
- end