Class: Rancher::Shell::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rancher/shell/cli.rb

Instance Method Summary collapse

Instance Method Details

#exec(command = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rancher/shell/cli.rb', line 19

def exec command = nil
  Config.load(
    'project' => options[:project],
    'container' => options[:container],
    'stack' => options[:stack],
    'command' => command,
  )
  instance = Rancher::Shell::Commands::Exec.new
  instance.setup_api!
  instance.retrieve_containers!
  instance.setup_websocket!
  instance.listen!
end

#list_containersObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rancher/shell/cli.rb', line 48

def list_containers
  Config.load(
    'project' => options[:project],
  )
  project = Config.get('project')
  api = Rancher::Shell::Api.new(
    host: project['api']['host'],
    user: project['api']['key'],
    pass: project['api']['secret'],
  )
  containers = api.get('containers?state=running').json['data']
  containers.each do |container|
    print container['id'].ljust 12
    print container['state'].ljust 12
    print container['name'].ljust 40
    print container['imageUuid'][7..-1].ljust 48
    print container['ports'] if container['ports'] && container['ports'] != ''
    print "\n"
  end
end

#list_projectsObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rancher/shell/cli.rb', line 34

def list_projects
  Config.load
  projects = Config.get('projects')
  projects.each do |key, project|
    print key.ljust 24
    print project['name'].ljust 32
    print project['api']['host'].ljust 32
    print project['stacks'].keys.join(', ') unless project['stacks'].nil?
    print "\n"
  end
end

#versionObject



11
12
13
# File 'lib/rancher/shell/cli.rb', line 11

def version
  puts "Rancher::Shell #{Rancher::Shell::VERSION}"
end