Class: Smash::CloudPowers::Node::Instance

Inherits:
Resource
  • Object
show all
Includes:
Smash::CloudPowers::Node
Defined in:
lib/cloud_powers/node/instance.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#call_name, #client, #linked, #meta, #remote_id, #tags, #type

Instance Method Summary collapse

Methods included from Smash::CloudPowers::Node

#batch_tag, #build_node, #create_node, #create_nodes, #node_config

Methods included from Zenv

#env_vars, #i_vars, #lsof_cwd, #pid, #proc_cwd, #process_search, #project_root, #project_root=, #ps_cwd, #system_vars, #zfind, #zselect

Methods included from Helpers

#create_logger, #log_file, #logger

Methods included from PathHelp

#common_delimiter, #expand_path, #file_exists?, #file_search, #filename?, #job_exist?, #job_path, #job_require_path, #path_search, #paths_gcd, #paths_lcd, #to_path, #to_pathname, #to_realpath, #touch, #zlib_path

Methods included from LogicHelp

#attr_map, #called_from, #i_var_hash, #instance_attr_accessor, #smart_retry, #update_message_body, #wait_until

Methods included from LangHelp

#deep_modify_keys_with, #extract!, #find_and_remove, #format_error_message, #from_json, #modify_keys_with, #to_basic_hash, #to_camel, #to_hyph, #to_i_var, #to_pascal, #to_ruby_file_name, #to_snake, #valid_json?, #valid_url?

Methods included from Auth

creds, region

Methods included from AwsResources

#image, #kinesis, #queue_poller, #region, #s3, #sns, #sqs

Methods included from Creatable

included

Constructor Details

#initialize(name:, client: ec2, **config) ⇒ Instance

Returns a new instance of Instance.



15
16
17
18
# File 'lib/cloud_powers/node/instance.rb', line 15

def initialize(name:, client: ec2, **config)
  super(name: name)
  @ec2 = client
end

Instance Attribute Details

#ec2Object

An Aws::EC2::Client. See Smash::CloudPowers::AwsResources#ec2()



13
14
15
# File 'lib/cloud_powers/node/instance.rb', line 13

def ec2
  @ec2
end

#nameObject

The name of the Aws::EC2 instance



11
12
13
# File 'lib/cloud_powers/node/instance.rb', line 11

def name
  @name
end

Instance Method Details

#create_resourceObject

Uses Aws::EC2#run_instances() to create nodes (Neurons or Cerebrums), at a rate of 0..(n <= 100) at a time, until the required number of instances has been started. The #instance_config() method is used to create instance configuration for the #run_instances method by using the opts hash that was provided as a parameter.

Parameters

  • opts Hash (optional) an optional instance configuration hash can be passed, which will override the values in the default configuration returned by #instance_config()



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloud_powers/node/instance.rb', line 30

def create_resource
  # response = ec2.run_instances(
  #   node_config(max_count: 1, self.to_h)
  # ).instances.first

  instance_attr_accessor response
  # id = @response[:instance_id]
  begin
    ec2.wait_until(:instance_running, instance_ids: [id]) do
      logger.info "waiting for #{ids.count} Neurons to start..."
    end
  rescue Aws::Waiters::Errors::WaiterFailed => e
    # TODO: retry stuff
    # redo unless (count += 1 <=3 )
  end

  yield self if block_given?
  self
end