13
14
15
16
17
18
19
20
21
22
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
|
# File 'lib/command.rb', line 13
def execute
options = {}
options[:all] = ''
opts = OptionParser.new do |o|
o.banner = 'Usage: vagrant route [options]'
o.separator ''
o.separator 'Options:'
o.separator ''
o.on('--all', 'Expose all routes') do
options[:all] = '--all-namespaces --config=/var/lib/origin/openshift.local.config/master/admin.kubeconfig'
end
end
argv = parse_options(opts)
return unless argv
with_target_vms(nil, single_target: true) do |machine|
machine.communicate.execute("oc get routes #{options[:all]}", sudo: false) do |type, data|
@result = data
end
@env.ui.info("Updating hosts file with new hostnames:\n#{routes_hostnames(@result).join(', ')}")
ip = machine.ssh_info[:host]
update_hosts(routes_hostnames(@result), ip)
end
rescue NoRoutesError
@env.ui.error('No routes are defined.')
rescue => e
case @result
when /.*the server has asked for the client to provide credentials.*/
@env.ui.error('You need to sign in and select a project in OpenShift first.')
when /.*oc: command not found.*/
@env.ui.error('oc command was not found on guest. Is OpenShift installed?')
when /.*cannot list all routes in the cluster*/
@env.ui.error('You need to be logged in as cluster admin to expose all routes.')
else
@env.ui.error("Unexpected error occured:\n\n#{e.message}")
end
end
|