Class: EksCli::Spotinst::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/eks_cli/spotinst/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(account_id: nil, api_token: nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eks_cli/spotinst/client.rb', line 9

def initialize(account_id: nil, api_token: nil)
  @account_id =  || ENV['SPOTINST_ACCOUNT_ID']
  @api_token = api_token || ENV['SPOTINST_API_TOKEN']
  if @account_id == nil
    raise "please set SPOTINST_ACCOUNT_ID environment variable"
  end

  if @api_token == nil
    raise "please set SPOTINST_API_TOKEN environment variable"
  end
  self.class.headers({"Authorization" => "Bearer #{@api_token}",
                      "Content-Type" => "application/json"})
end

Instance Method Details

#import_asg(region, asg_name, instance_types) ⇒ Object



23
24
25
26
# File 'lib/eks_cli/spotinst/client.rb', line 23

def import_asg(region, asg_name, instance_types)
  self.class.post("/aws/ec2/group/autoScalingGroup/import?region=#{region}&accountId=#{@account_id}&autoScalingGroupName=#{asg_name}",
                  body: {group: {spotInstanceTypes: instance_types} }.to_json)
end

#list_groupsObject



28
29
30
# File 'lib/eks_cli/spotinst/client.rb', line 28

def list_groups
  self.class.get("/aws/ec2/group?accountId=#{@account_id}")
end