Class: OcpCommander

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/commander/OcpCommander.rb

Instance Method Summary collapse

Instance Method Details

#runObject

include whatever modules you need



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/commander/OcpCommander.rb', line 23

def run

  program :name, 'ocp'
  program :version, '0.0.1'
  program :description, 'A Ruby command line tool to interact with OpenShift Container Platform'

  global_option('-t','--token [TOKEN]','Provide a token.  This option will over-ride what is in a config file')
  global_option('--clientcertfile [CLIENTCERT]','Provide a path to the client certificate file.  This option will over-ride what is in a config file')
  global_option('--clientkeyfile [CLIENTKEY]','Provide a path to the client key file.  This option will over-ride what is in a config file')
  global_option('--clientcafile [CLIENTCA]','Provide a path to the client CA certificate file.  This option will over-ride what is in a config file')
  global_option('-c','--config [CONFIG]','Provide a config file.  See README.md for an example')
  global_option('-m','--master [MASTER]','OpenShift Cluster to which wish to connect.  This option will over-ride what is in a config file')
  global_option('-n','--noverifyssl','Do not verify SSL certificate of master.  This option will over-ride what is in a config file')
  global_option('-o','--output [OUTPUT]',[:yaml, :json], "Select the output format")
  global_option('-d','--debug', "Dump debug information to console")
  global_option('-p','--pretty', "Generate pretty output where possible")

  command :getocpapi do |c|
    c.syntax = 'ocp getocpapi [options]'
    c.description = 'Retrieve the OpenShift Container Platform API'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getoapi,
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      ocpapi = OcpApi.new
      ocpapi.setup(ocpconfig)
      puts "#{ocpapi}"
    end
  end

  command :getapi do |c|
    c.syntax = 'ocp getapi [options]'
    c.summary = 'Retrieve the Kubernetes API'
    c.description = ''
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getapi
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      api = Api.new
      api.setup(ocpconfig)
      puts "#{api.showapi}"
    end
  end

  command :createproject do |c|
    c.syntax = 'ocp createproject [options]'
    c.summary = 'Create a project request'
    c.description = 'Create a project request'
    c.option '--name PROJECTNAME', String, 'The name for the project'
    c.option '--description [DESCRIPTION]', String, 'The description for the project'
    c.option '--displayname [DISPLAYNAME]', String, 'The displayname for the project'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getapi

      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      projreq = ProjectRequest.new
      projreq.setup(ocpconfig)

      data = projreq.createprojectrequest(options.name, options.description, options.displayname)

      puts "#{data}"
    end
  end

  command :deleteproject do |c|
    c.syntax = 'ocp deleteproject [options]'
    c.summary = 'Delete a project'
    c.description = 'Delete a project'
    c.option '--name PROJECTNAME', String, 'The name for the project'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getapi

      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      project = Project.new
      project.setup(ocpconfig)

      data = project.deleteproject(options.name)

      puts "#{data}"
    end
  end

  command :listpolicies do |c|
    c.syntax = 'ocp listpolicies [options]'
    c.description = 'Retrieve the Policies for a NameSpace'
    c.option '--name PROJECTNAME', String, 'The name for the project'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getoapi,
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      policy = Policy.new
      policy.setup(ocpconfig)
      puts "#{policy}"
    end
  end

  command :listoauthclientauthorizations do |c|
    c.syntax = 'ocp oauthclientauthorizations [options]'
    c.description = 'Retrieve the OAuthClientAuthorizations'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getoapi,
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      oauthpolicy = OAuthClientAuthorization.new
      oauthpolicy.setup(ocpconfig)
      puts "#{oauthpolicy}"
    end
  end

  command :listroles do |c|
    c.syntax = 'ocp listroles [options]'
    c.description = 'Retrieve the Roles'
    c.option '--name [PROJECTNAME]', String, 'Optionally the name of the project'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getoapi,
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      roles = nil
      if options.name.nil?
        roles = Role.new
      else
        roles = Role.new(options.name)
      end
      roles.setup(ocpconfig)

      puts "#{roles}"
    end
  end

  command :listrolebindings do |c|
    c.syntax = 'ocp listrolebindings [options]'
    c.description = 'Retrieve the Roles Bindings'
    c.option '--name [PROJECTNAME]', String, 'Optionally the name of the project'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getoapi,
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end
      roles = nil
      if options.name.nil?
        roles = RoleBinding.new
      else
        roles = RoleBinding.new(options.name)
      end
      roles.setup(ocpconfig)


      puts "#{roles}"
    end
  end

  command :create_role_binding do |c|
    c.syntax = 'ocp createrolebinding [options]'
    c.description = 'Create a Project Roles Binding'
    c.option '--name PROJECTNAME', String, 'The name of the project'
    c.option '--user USERNAME', String, 'The name of the user'
    c.option '--role ROLE', String, 'The role to add to the user'
    c.action do |args, options|
      # Do something or c.when_called Ocp::Commands::Getoapi,
      ocpconfig = OcpConfig.new
      ocpconfig.set_config_with_options(options)
      if ocpconfig.debug
        puts "Config: #{ocpconfig.inspect}"
      end

      roles = RoleBinding.new(options.name)

      roles.setup(ocpconfig)
      resp = roles.create_role_binding(options.user, options.role)
      puts "#{resp}"

    end
  end

  run!
end