Module: Smash::CloudPowers::Node

Includes:
Auth, Helpers, Zenv
Included in:
Smash::CloudPowers, Instance
Defined in:
lib/cloud_powers/node.rb,
lib/cloud_powers/node/instance.rb

Defined Under Namespace

Classes: Instance

Instance Method Summary collapse

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

Instance Method Details

#batch_tag(ids, tags, client: ec2) ⇒ Object

This method adds certain tags to an array of resource ids.

Parameters

  • ids Array|String - an Array or a single instance id, as an Array of Strings or a single String

  • tags Array - an Array of key, value hash

Returns

  • Returns an empty response.

Examples

create_tag('ami-2342354', tags: { key: "stack", value: "production"})
or
create_tag(['ami-2432342'], tags: [{ key: 'stack', value: 'production' }])
or any permutation of those


28
29
30
31
32
# File 'lib/cloud_powers/node.rb', line 28

def batch_tag(ids, tags, client: ec2)
  tags_opts = { resources: ids, tags: tags }
  ec2.create_tags(tags_opts)
  logger.info "tags for #{ids} created"
end

#build_node(name:, client: ec2, **config) ⇒ Object



34
35
36
37
38
39
# File 'lib/cloud_powers/node.rb', line 34

def build_node(name:, client: ec2, **config)
  resp = Smash::CloudPowers::Node::Instance.build(name: name, client: ec2, **config)
  i_var_name = "#{name}_node"
  instance_attr_accessor i_var_name
  instance_variable_set(to_i_var(i_var_name), resp)
end

#create_node(name:, client: ec2, **config) ⇒ Object

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()



51
52
53
54
55
56
# File 'lib/cloud_powers/node.rb', line 51

def create_node(name:, client: ec2, **config)
  resp = Smash::CloudPowers::Node::Instance.create!(name: name, client: ec2, **config)
  i_var_name = "#{name}_node"
  instance_attr_accessor i_var_name
  instance_variable_set(to_i_var(i_var_name), resp)
end

#create_nodes(name:, client: ec2, **config) ⇒ Object

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()

Returns Array of responses from



71
72
73
74
75
76
# File 'lib/cloud_powers/node.rb', line 71

def create_nodes(name:, client: ec2, **config)
  resp = ec2.run_instances(node_config(config)).instances
  i_var_name = "#{name}_nodes"
  instance_attr_accessor i_var_name
  instance_variable_set(to_i_var(i_var_name), resp)
end

#node_config(**config) ⇒ Object

These are sensible defaults that can be overriden by providing a Hash as a param.

Parameters

  • opts Hash (optional) the opts Hash should have values that should be used instead of the default configuration.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/cloud_powers/node.rb', line 84

def node_config(**config)
  {
    dry_run:                                zfind(:testing) || false,
    image_id:                               image(zfind(:node_image)).image_id, # image(:neuron).image_id
    instance_type:                          't2.nano',
    min_count:                              config[:max_count] || 0,
    max_count:                              0,
    key_name:                               'crawlBot',
    security_groups:                        ['webCrawler'],
    security_group_ids:                     ['sg-940edcf2'],
    placement:                              { availability_zone: 'us-west-2c' },
    disable_api_termination:                'false',
    instance_initiated_shutdown_behavior:   'terminate'
  }.merge(config)
end