class DTK::Client::Provider

Public Class Methods

all_children() click to toggle source
# File lib/commands/thor/provider.rb, line 25
def self.all_children()
  [:target]
end
override_allowed_methods() click to toggle source
# File lib/commands/thor/provider.rb, line 33
def self.override_allowed_methods()
  return DTK::Shell::OverrideTasks.new({
    :command_only => {
      :target => [
        ['delete-and-destroy',"delete-and-destroy TARGET-NAME","# Deletes target"],
        ['list',"list","# Lists available targets."]

      ]
    },
    :identifier_only => {
      :target      => [
        ['list-nodes',"list-nodes","# Lists node instances in given targets."],
        ['list-services',"list-services","# Lists assembly instances in given targets."]
      ]
    }
  })
end
valid_child?(name_of_sub_context) click to toggle source
# File lib/commands/thor/provider.rb, line 51
def self.valid_child?(name_of_sub_context)
  Provider.valid_children().include?(name_of_sub_context.to_sym)
end
valid_children() click to toggle source
# File lib/commands/thor/provider.rb, line 21
def self.valid_children()
  [:target]
end
validation_list(context_params) click to toggle source
# File lib/commands/thor/provider.rb, line 29
def self.validation_list(context_params)
  get_cached_response(:provider, "target/list", {:subtype => :template })
end

Public Instance Methods

create_provider_ec2(context_params) click to toggle source
# File lib/commands/thor/provider.rb, line 60
def create_provider_ec2(context_params)
  provider_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
  provider_type = 'ec2'

  iaas_properties = Hash.new

  keypair, security_group = context_params.retrieve_thor_options([:keypair, :security_group], options)

  iaas_properties.merge!(:keypair => keypair) if keypair
  if security_group
    if security_group.end_with?(',')
      raise DtkValidationError.new("Multiple security groups should be separated with ',' and without spaces between them (e.g. --security_groups gr1,gr2,gr3,...) ")
    end

    security_groups = security_group.split(',')

    if (security_groups.empty? || security_groups.size==1)
      iaas_properties.merge!(:security_group => security_group)
    else
      iaas_properties.merge!(:security_group_set => security_groups)
    end
  end

  result = Shell::InteractiveWizard::interactive_user_input(
    {'IAAS Credentials' => { :type => :group, :options => [
          {:key    => {}},
          {:secret => {}}
      ]}})
  access_key, secret_key = result['IAAS Credentials'].values_at(:key, :secret)
  iaas_properties.merge!(:key => access_key,:secret => secret_key)

  # Remove sensitive readline history
  OsUtil.pop_readline_history(2)

  post_body =  {
    :iaas_properties => iaas_properties,
    :provider_name   => provider_name,
    :iaas_type       => 'ec2',
    :no_bootstrap    => ! options.bootstrap?
  }

  response = post rest_url("target/create_provider"), post_body
  @@invalidate_map << :provider

  response
end
create_provider_physical(context_params) click to toggle source
# File lib/commands/thor/provider.rb, line 108
def create_provider_physical(context_params)
  provider_name = context_params.retrieve_arguments([:option_1!],method_argument_names)

  # Remove sensitive readline history
  OsUtil.pop_readline_history(2)

  post_body =  {
    :provider_name => provider_name,
    :iaas_type => 'physical'
  }

  response = post rest_url("target/create_provider"), post_body
  @@invalidate_map << :provider

  response
end
decompose_provider_type_and_name(composed_name) click to toggle source
# File lib/commands/thor/provider.rb, line 219
def decompose_provider_type_and_name(composed_name)
  provider_type, provider_name = composed_name.split(':')

  if (provider_type.nil? || provider_name.nil? || provider_type.empty? || provider_name.empty?)
    raise DtkValidationError.new("Provider name and type are required parameters and should be provided in format PROVIDER-TYPE:PROVIDER-NAME")
  end

  return [provider_type, provider_name]
end
delete_and_destroy(context_params) click to toggle source
# File lib/commands/thor/provider.rb, line 195
def delete_and_destroy(context_params)
  provider_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 provider '#{provider_id}' and all target and service instances under it" +'?')
  end

  post_body = {
    :target_id => provider_id,
    :type      => 'template'
  }

  @@invalidate_map << :provider

  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
list(context_params) click to toggle source
# File lib/commands/thor/provider.rb, line 167
def list(context_params)
  if context_params.is_there_command?(:"target")
    list_targets(context_params)
  else
    response  = post rest_url("target/list"), { :subtype => :template }
    response.render_table(:provider)
  end
end
list_targets(context_params) click to toggle source
# File lib/commands/thor/provider.rb, line 186
def list_targets(context_params)
  provider_id = context_params.retrieve_arguments([:provider_id!],method_argument_names)

  response = post rest_url("target/list"), { :subtype => :instance, :parent_id => provider_id }
  response.render_table(:target)
end