Class: Kontena::Plugin::Cloud::Node::RebootCommand

Inherits:
Command
  • Object
show all
Includes:
Cli::Common, Common, Platform::Common
Defined in:
lib/kontena/plugin/cloud/node/reboot_command.rb

Constant Summary

Constants included from CloudCommand

CloudCommand::PLATFORM_NOT_SELECTED_ERROR

Instance Method Summary collapse

Methods included from Common

#cached_platforms_by_id, #compute_client, #compute_url, #config, #get_platform

Methods included from Platform::Common

#cached_platforms, #current_organization, #current_platform, #fetch_platforms, #fetch_platforms_for_org, #find_platform_by_name, #login_to_platform, #parse_platform_name, #platform_config_exists?, #prompt_platform, #require_platform

Methods included from CloudCommand

#verify_current_grid, #verify_current_master, #verify_current_master_token

Instance Method Details

#default_organizationObject



28
29
30
31
32
33
34
# File 'lib/kontena/plugin/cloud/node/reboot_command.rb', line 28

def default_organization
  unless current_master
    exit_with_error "Organization is required"
  end
  org, _ = parse_platform_name(current_master.name)
  org
end

#executeObject



15
16
17
18
19
20
21
# File 'lib/kontena/plugin/cloud/node/reboot_command.rb', line 15

def execute
  node = find_node(name)
  exit_with_error "Node not found" unless node
  spinner "Sending reboot request to #{pastel.cyan(name)}" do
    compute_client.post("/organizations/#{self.organization}/nodes/#{node.dig('id')}/reboot", {})
  end
end

#find_node(name) ⇒ Object



23
24
25
26
# File 'lib/kontena/plugin/cloud/node/reboot_command.rb', line 23

def find_node(name)
  nodes = compute_client.get("/organizations/#{self.organization}/nodes")['data']
  nodes.find { |n| n.dig('attributes', 'name') == name }
end