class DTK::Client::Target

Constants

ValidImportTypes

Public Class Methods

alternate_identifiers() click to toggle source
# File lib/commands/thor/target.rb, line 30
def self.alternate_identifiers()
  return ['PROVIDER']
end
extended_context() click to toggle source
# File lib/commands/thor/target.rb, line 34
def self.extended_context()
  {
    :context => {
      # want auto complete for --provider option
      "--provider" => "provider"
    }
  }
end
pretty_print_cols() click to toggle source
# File lib/commands/thor/target.rb, line 26
def self.pretty_print_cols()
  PPColumns.get(:target)
end
validation_list(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 138
def self.validation_list(context_params)
  provider_id = context_params.retrieve_arguments([:provider_id])

  if provider_id
    # if assembly_id is present we're loading nodes filtered by assembly_id
    post_body = {
      :subtype   => :instance,
      :parent_id => provider_id
    }

    response = get_cached_response(:provider_target, "target/list", post_body)
  else
    # otherwise, load all nodes
    response = get_cached_response(:target, "target/list", { :subtype => :instance })
  end

  response
end

Public Instance Methods

create_target_ec2_classic(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 111
def create_target_ec2_classic(context_params)
  option_list = [:provider!, :region!, :keypair, :security_group]
  response = Common::CreateTarget.new(self, context_params).execute(:ec2_classic,option_list)
  @@invalidate_map << :target
  response
end
create_target_ec2_vpc(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 124
def create_target_ec2_vpc(context_params)
  option_list = [:provider!, :subnet!, :region!, :keypair, :security_group]
  response = Common::CreateTarget.new(self, context_params).execute(:ec2_vpc,option_list)
  @@invalidate_map << :target
  response
end
delete_and_destroy(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 193
def delete_and_destroy(context_params)
  target_id  = context_params.retrieve_arguments([:option_1!],method_argument_names)

  unless options.force?
    return unless Console.confirmation_prompt("Are you sure you want to delete target '#{target_id}' (all services/nodes that belong to this target will be deleted as well)'"+'?')
  end

  post_body = {
    :target_id => target_id,
    :type      => 'instance'
  }

  @@invalidate_map << :target

  response = post(rest_url("target/delete_and_destroy"),post_body)
  return response unless response.ok?
  if info_array = response.data['info']
    info_array.each{|info_msg|OsUtil.print(info_msg, :yellow)}
  end
  Response::Ok.new()
end
import_nodes(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 59
def import_nodes(context_params)
  target_id   = context_params.retrieve_arguments([:target_id!],method_argument_names)
  source = context_params.retrieve_thor_options([:source!], options)

  parsed_source = source.match(/^(\w+):(.+)/)
  raise DtkValidationError, "Invalid source! Valid source should contain source_type:source_path (e.g. --source file:path/to/file.yaml)." unless parsed_source

  import_type = parsed_source[1]
  path = parsed_source[2]

  raise DtkValidationError, "We do not support '#{import_type}' as import source at the moment. Valid sources: #{ValidImportTypes}" unless ValidImportTypes.include?(import_type)

  post_body = {:target_id => target_id}

  if import_type.eql?('file')
    inventory_data = parse_inventory_file(path)
    post_body.merge!(:inventory_data => inventory_data)
  end

  response  = post rest_url("target/import_nodes"), post_body
  return response unless response.ok?

  if response.data.empty?
    OsUtil.print("No new nodes to import!", :yellow)
  else
    OsUtil.print("Successfully imported nodes:", :yellow)
    response.data.each do |node|
      OsUtil.print("#{node}", :yellow)
    end
  end
end
info(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 50
def info(context_params)
  target_id   = context_params.retrieve_arguments([:target_id!],method_argument_names)

  post_body = {:target_id => target_id}
  post rest_url('target/info'), post_body
end
install_agents(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 99
def install_agents(context_params)
  target_id   = context_params.retrieve_arguments([:target_id!],method_argument_names)

  post_body = {:target_id => target_id}
  post rest_url("target/install_agents"), post_body
end
list(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 158
def list(context_params)
  provider_id, target_id, about = context_params.retrieve_arguments([:provider_id, :target_id, :option_1],method_argument_names||="")

  if target_id.nil?
    post_body = {
      :subtype   => :instance,
      :parent_id => provider_id
    }
    response  = post rest_url("target/list"), post_body

    response.render_table(:target)
  else
    post_body = {
      :target_id => target_id,
      :about => about
    }

    case about
      when "nodes"
        response  = post rest_url("target/info_about"), post_body
        data_type =  :node
      when "assemblies"
        post_body.merge!(:detail_level => 'nodes', :include_workspace => true)
        response  = post rest_url("target/info_about"), post_body
        data_type =  :assembly
      else
        raise_validation_error_method_usage('list')
    end

    response.render_table(data_type)
  end
end
list_nodes(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 44
def list_nodes(context_params)
  context_params.method_arguments = ["nodes"]
  list(context_params)
end
list_services(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 133
def list_services(context_params)
  context_params.method_arguments = ["assemblies"]
  list(context_params)
end
set_default_target(context_params) click to toggle source
# File lib/commands/thor/target.rb, line 93
def set_default_target(context_params)
  target_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
  post rest_url("target/set_default"), { :target_id => target_id }
end