cloud_powers 0.2.7 → 0.2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.rdoc.mdown +180 -0
- data/Rakefile +5 -0
- data/cloud_powers.gemspec +1 -1
- data/lib/cloud_powers/auth.rb +24 -10
- data/lib/cloud_powers/aws_resources.rb +70 -114
- data/lib/cloud_powers/context.rb +66 -31
- data/lib/cloud_powers/helper.rb +36 -33
- data/lib/cloud_powers/node.rb +2 -2
- data/lib/cloud_powers/self_awareness.rb +18 -11
- data/lib/cloud_powers/synapse/broadcast/broadcast.rb +27 -9
- data/lib/cloud_powers/synapse/pipe/pipe.rb +77 -31
- data/lib/cloud_powers/synapse/queue/board.rb +78 -32
- data/lib/cloud_powers/synapse/queue/queue.rb +164 -38
- data/lib/cloud_powers/synapse/synapse.rb +7 -6
- data/lib/cloud_powers/version.rb +1 -1
- data/lib/cloud_powers/zenv.rb +11 -11
- data/lib/cloud_powers.rb +10 -0
- data/lib/stubs/aws_stubs.rb +132 -4
- metadata +4 -3
    
        data/lib/cloud_powers/context.rb
    CHANGED
    
    | @@ -17,16 +17,19 @@ module Smash | |
| 17 17 |  | 
| 18 18 | 
             
                  # Attempts to create a Context out of the argument(s) you've
         | 
| 19 19 | 
             
                  # passed.
         | 
| 20 | 
            -
                  # | 
| 21 | 
            -
                  # | 
| 22 | 
            -
                  # | 
| 23 | 
            -
                  # | 
| 24 | 
            -
                  # | 
| 25 | 
            -
                  # | 
| 26 | 
            -
                  # | 
| 27 | 
            -
                  # | 
| 28 | 
            -
                  #  | 
| 29 | 
            -
                  # | 
| 20 | 
            +
                  #
         | 
| 21 | 
            +
                  # Parameters
         | 
| 22 | 
            +
                  # * args +Hash+|+JSON+|+Array+|+enumerable list+
         | 
| 23 | 
            +
                  # * * expample +Hash+:
         | 
| 24 | 
            +
                  # * * * each key is a module or class that is in CloudPowers and each value
         | 
| 25 | 
            +
                  #       is either an array of configurations information or a single configuration.
         | 
| 26 | 
            +
                  #         { task: 'demo', queue: [:backlog, :sned], pipe: :status_stream }
         | 
| 27 | 
            +
                  # * * expample Array
         | 
| 28 | 
            +
                  # * * * each key is followed by 0..n valid configurations information
         | 
| 29 | 
            +
                  #         [:task, 'demo', :queue, :backlog, :sned, :pipe, :status_stream]
         | 
| 30 | 
            +
                  #
         | 
| 31 | 
            +
                  # Returns
         | 
| 32 | 
            +
                  # +Smash::Context+
         | 
| 30 33 | 
             
                  def initialize(args)
         | 
| 31 34 | 
             
                    unless valid_args?(args)
         | 
| 32 35 | 
             
                      raise ArgumentError.new 'Can be either a Hash, JSON, or an Enumerable ' +
         | 
| @@ -36,8 +39,12 @@ module Smash | |
| 36 39 | 
             
                    @structure = decipher(args)
         | 
| 37 40 | 
             
                  end
         | 
| 38 41 |  | 
| 39 | 
            -
                  #  | 
| 40 | 
            -
                  #  | 
| 42 | 
            +
                  # Decipher figures out which translation method to use by making some simple type checks, etc.
         | 
| 43 | 
            +
                  # and then routing the args to the correct method.
         | 
| 44 | 
            +
                  #
         | 
| 45 | 
            +
                  # Notes
         | 
| 46 | 
            +
                  # * See +#translate_json()+
         | 
| 47 | 
            +
                  # * See +#translate_list()+
         | 
| 41 48 | 
             
                  def decipher(args)
         | 
| 42 49 | 
             
                    case args
         | 
| 43 50 | 
             
                    when Hash
         | 
| @@ -50,33 +57,61 @@ module Smash | |
| 50 57 | 
             
                  end
         | 
| 51 58 |  | 
| 52 59 | 
             
                  # Creates a flat Array of the 2-D Array that gets returned from `#simplify()`
         | 
| 53 | 
            -
                  # | 
| 60 | 
            +
                  #
         | 
| 61 | 
            +
                  # Returns +Array+
         | 
| 62 | 
            +
                  #
         | 
| 63 | 
            +
                  # Example
         | 
| 64 | 
            +
                  #   example_context.structure
         | 
| 65 | 
            +
                  #   # => { task: 'demo', queue: [:backlog, :sned], pipe: [:status_stream] }
         | 
| 66 | 
            +
                  #   example.flatten
         | 
| 67 | 
            +
                  #   # => [:task, 'demo', :queue, :backlog, :sned, :pipe, :status_stream]
         | 
| 68 | 
            +
                  #
         | 
| 69 | 
            +
                  # Notes
         | 
| 70 | 
            +
                  # * See +#simplify()
         | 
| 71 | 
            +
                  # * See +#Array::flatten()+
         | 
| 54 72 | 
             
                  def flatten
         | 
| 55 73 | 
             
                    simplify.flatten
         | 
| 56 74 | 
             
                  end
         | 
| 57 75 |  | 
| 58 76 | 
             
                  # Create an array version of @sructure by calling `#to_a()` on it
         | 
| 59 | 
            -
                  # | 
| 60 | 
            -
                  #  | 
| 77 | 
            +
                  #
         | 
| 78 | 
            +
                  # Returns
         | 
| 79 | 
            +
                  # <tt>Array[Array..n]</tt>
         | 
| 80 | 
            +
                  #
         | 
| 81 | 
            +
                  # Example
         | 
| 82 | 
            +
                  #   example_context.structure
         | 
| 83 | 
            +
                  #   # => { task: 'demo', queue: [:backlog, :sned], pipe: [:status_stream] }
         | 
| 84 | 
            +
                  #   example.simplify
         | 
| 85 | 
            +
                  #   # => [:task, 'demo', :queue, [:backlog, :sned], :pipe, [:status_stream]]
         | 
| 86 | 
            +
                  #
         | 
| 87 | 
            +
                  # Notes
         | 
| 88 | 
            +
                  # * This uses the different Constants, like Smash, Synapse and anything it can find
         | 
| 89 | 
            +
                  #   to decide what should be used as a key and what its following values array should
         | 
| 90 | 
            +
                  #   contain.  It basically says:
         | 
| 91 | 
            +
                  #   1. if the nth item is a known key (from the above search), add it as an object in the Array.
         | 
| 92 | 
            +
                  #   2. else, add it to the last sub-Array
         | 
| 93 | 
            +
                  #   3. move to n+1 in the +structure Hash+
         | 
| 94 | 
            +
                  # * TODO: Check if this has a limit to n-layers
         | 
| 61 95 | 
             
                  def simplify
         | 
| 62 96 | 
             
                    @structure.to_a
         | 
| 63 97 | 
             
                  end
         | 
| 64 98 |  | 
| 65 99 | 
             
                  # A Hash that represents the resources and some configuration for them
         | 
| 66 | 
            -
                  # | 
| 100 | 
            +
                  #
         | 
| 101 | 
            +
                  # Returns +Hash+
         | 
| 67 102 | 
             
                  def structure
         | 
| 68 103 | 
             
                    modify_keys_with(@structure) { |key| key.to_sym }
         | 
| 69 104 | 
             
                  end
         | 
| 70 105 |  | 
| 71 106 | 
             
                  # Valid scheme for @structure is assured by running the arguments through
         | 
| 72 | 
            -
                  # the decipher method, which is how @structure is set in  | 
| 107 | 
            +
                  # the decipher method, which is how @structure is set in +#new(args)+
         | 
| 73 108 | 
             
                  def structure=(args)
         | 
| 74 109 | 
             
                    @structure = decipher(args)
         | 
| 75 110 | 
             
                  end
         | 
| 76 111 |  | 
| 77 112 | 
             
                  # Parse the given JSON
         | 
| 78 | 
            -
                  #  | 
| 79 | 
            -
                  #  | 
| 113 | 
            +
                  # Parameters: json_string <String::Json>
         | 
| 114 | 
            +
                  # Returns <Hash>
         | 
| 80 115 | 
             
                  def translate_json(json_string)
         | 
| 81 116 | 
             
                    begin
         | 
| 82 117 | 
             
                      JSON.parse(json_string)
         | 
| @@ -124,19 +159,19 @@ module Smash | |
| 124 159 | 
             
                  #        ...
         | 
| 125 160 | 
             
                  #      }
         | 
| 126 161 | 
             
                  #      ```
         | 
| 127 | 
            -
                  #  | 
| 162 | 
            +
                  # Returns Hash
         | 
| 128 163 | 
             
                  #   If `#valid_package_hash?()` is called on this Hash, it will return true
         | 
| 129 164 | 
             
                  def translate_list(list)
         | 
| 130 165 | 
             
                    list.first.kind_of?(Enumerable) ? translate_simplified(list) : translate_flattened(list)
         | 
| 131 166 | 
             
                  end
         | 
| 132 167 |  | 
| 133 168 | 
             
                  # Translates an Array into a valid @structure Hash
         | 
| 134 | 
            -
                  #  | 
| 169 | 
            +
                  # Parameters arr <Array>
         | 
| 135 170 | 
             
                  #   e.g.
         | 
| 136 171 | 
             
                  #   ```Ruby
         | 
| 137 172 | 
             
                  #   [:task, 'demo', :queue, 'name1', {other config hash},...,:pipe, 'name1']
         | 
| 138 173 | 
             
                  #   ```
         | 
| 139 | 
            -
                  #  | 
| 174 | 
            +
                  # Returns Hash
         | 
| 140 175 | 
             
                  #   calling `#valid_hash_format?()` on returned Hash will return true
         | 
| 141 176 | 
             
                  def translate_flattened(list)
         | 
| 142 177 | 
             
                    arr = list.to_a
         | 
| @@ -155,7 +190,7 @@ module Smash | |
| 155 190 | 
             
                  end
         | 
| 156 191 |  | 
| 157 192 | 
             
                  # Translates a 2D Array into a valid @structure Hash
         | 
| 158 | 
            -
                  #  | 
| 193 | 
            +
                  # Parameters arr <Array>
         | 
| 159 194 | 
             
                  #   e.g.
         | 
| 160 195 | 
             
                  #   ```
         | 
| 161 196 | 
             
                  #     [
         | 
| @@ -169,7 +204,7 @@ module Smash | |
| 169 204 | 
             
                  #   - First object of each inner-Array is the key
         | 
| 170 205 | 
             
                  #   - All following values in that inner Array are separate configuration
         | 
| 171 206 | 
             
                  #     information pieces that can be used in the `#create!()` method for that particular resource
         | 
| 172 | 
            -
                  #  | 
| 207 | 
            +
                  # Returns Hash
         | 
| 173 208 | 
             
                  #   well formatted for the @structure
         | 
| 174 209 | 
             
                  def translate_simplified(arr)
         | 
| 175 210 | 
             
                    arr.inject({}) do |hash, key_config_map|
         | 
| @@ -181,7 +216,7 @@ module Smash | |
| 181 216 | 
             
                  end
         | 
| 182 217 |  | 
| 183 218 | 
             
                  # Uses `#to_json()` on the @structure
         | 
| 184 | 
            -
                  #  | 
| 219 | 
            +
                  # Returns Hash
         | 
| 185 220 | 
             
                  def to_json
         | 
| 186 221 | 
             
                    structure.to_json
         | 
| 187 222 | 
             
                  end
         | 
| @@ -190,8 +225,8 @@ module Smash | |
| 190 225 | 
             
                  # class _should_ exist in.  It can be a vanilla version, where the @structure
         | 
| 191 226 | 
             
                  # is a Hash, structured correctly or it can be serialized into JSON or it can
         | 
| 192 227 | 
             
                  # be an Array
         | 
| 193 | 
            -
                  #  | 
| 194 | 
            -
                  #  | 
| 228 | 
            +
                  # Parameters args String
         | 
| 229 | 
            +
                  # Returns Boolean
         | 
| 195 230 | 
             
                  def valid_args?(args)
         | 
| 196 231 | 
             
                    case args
         | 
| 197 232 | 
             
                    when Hash
         | 
| @@ -208,16 +243,16 @@ module Smash | |
| 208 243 | 
             
                  # Makes sure that the list is enumerable and that at least the first term
         | 
| 209 244 | 
             
                  # is a resource name from Smash::CloudPowers.  All other objects can
         | 
| 210 245 | 
             
                  # potentially be configurations.
         | 
| 211 | 
            -
                  #  | 
| 212 | 
            -
                  #  | 
| 246 | 
            +
                  # Parameters list <Array|Enumerable>
         | 
| 247 | 
            +
                  # Returns Boolean
         | 
| 213 248 | 
             
                  def valid_array_format?(list)
         | 
| 214 249 | 
             
                    use = list.first.kind_of?(Enumerable) ? list.first.first : list.first
         | 
| 215 250 | 
             
                    ((list.kind_of? Enumerable) && (available_resources.include?(to_pascal(use).to_sym)))
         | 
| 216 251 | 
             
                  end
         | 
| 217 252 |  | 
| 218 253 | 
             
                  # Makes sure that each key is the name of something CloudPowers can interact with
         | 
| 219 | 
            -
                  #  | 
| 220 | 
            -
                  #  | 
| 254 | 
            +
                  # Parameters hash <Hash>
         | 
| 255 | 
            +
                  # Returns Boolean
         | 
| 221 256 | 
             
                  def valid_hash_format?(hash)
         | 
| 222 257 | 
             
                    keys_arr = hash.keys.map { |key| to_pascal(key).to_sym }
         | 
| 223 258 | 
             
                    (keys_arr - available_resources).empty?
         | 
    
        data/lib/cloud_powers/helper.rb
    CHANGED
    
    | @@ -10,16 +10,19 @@ module Smash | |
| 10 10 |  | 
| 11 11 | 
             
                  # Sets an Array of instance variables, individually to a value that a
         | 
| 12 12 | 
             
                  # user given block returns.
         | 
| 13 | 
            -
                  # | 
| 14 | 
            -
                  # | 
| 13 | 
            +
                  #
         | 
| 14 | 
            +
                  # Parameters
         | 
| 15 | 
            +
                  #
         | 
| 16 | 
            +
                  # * keys +Array+
         | 
| 17 | 
            +
                  # * * each object will be used as the name for the instance variable that
         | 
| 15 18 | 
             
                  #     your block returns
         | 
| 16 | 
            -
                  #  | 
| 17 | 
            -
                  #   * this is called for each object in the Array and is used as the value
         | 
| 19 | 
            +
                  # +block+ (optional)
         | 
| 20 | 
            +
                  #   * this block is called for each object in the Array and is used as the value
         | 
| 18 21 | 
             
                  #   for the instance variable that is being named and created for each key
         | 
| 19 | 
            -
                  #  | 
| 22 | 
            +
                  # Returns Array
         | 
| 20 23 | 
             
                  #   * each object will either be the result of `#instance_variable_set(key, value)`
         | 
| 21 24 | 
             
                  #     or instance_variable_get(key)
         | 
| 22 | 
            -
                  #  | 
| 25 | 
            +
                  # Example
         | 
| 23 26 | 
             
                  #   keys = ['foo', 'bar', 'yo']
         | 
| 24 27 | 
             
                  #
         | 
| 25 28 | 
             
                  #   attr_map!(keys) { |key| sleep 1; "#{key}:#{Time.now.to_i}" }
         | 
| @@ -37,7 +40,7 @@ module Smash | |
| 37 40 |  | 
| 38 41 | 
             
                  # This is a way to find out if you are trying to work with a resource
         | 
| 39 42 | 
             
                  # available to CloudPowers
         | 
| 40 | 
            -
                  #  | 
| 43 | 
            +
                  # Returns <Array>
         | 
| 41 44 | 
             
                  #   * Use `.constants` to find all the modules and classes available.
         | 
| 42 45 | 
             
                  # Notes:
         | 
| 43 46 | 
             
                  #   TODO: make this smartly pick up all the objects, within reason and
         | 
| @@ -64,17 +67,17 @@ module Smash | |
| 64 67 |  | 
| 65 68 | 
             
                  # Allows you to modify all keys, including nested, with a block that you pass.
         | 
| 66 69 | 
             
                  # If no block is passed, a copy is returned.
         | 
| 67 | 
            -
                  #  | 
| 70 | 
            +
                  # Parameters
         | 
| 68 71 | 
             
                  #   * params Hash|Array
         | 
| 69 72 | 
             
                  # === @&block (optional)
         | 
| 70 73 | 
             
                  #   * should modify the key and return that value so it can be used in the copy
         | 
| 71 | 
            -
                  #  | 
| 74 | 
            +
                  # Returns
         | 
| 72 75 | 
             
                  #   * a copy of the given Array or Hash, with all Hash keys modified
         | 
| 73 76 | 
             
                  # === Sample use:
         | 
| 74 77 | 
             
                  #   hash = { 'foo' => 'v1', 'bar' => { fleep: { 'florp' => 'yo' } } }
         | 
| 75 78 | 
             
                  #   modify_keys_with(hash) { |key| key.to_sym }
         | 
| 76 79 | 
             
                  #   # => { foo: 'v1', bar: { fleep: { florp: 'yo' } } }
         | 
| 77 | 
            -
                  #  | 
| 80 | 
            +
                  # Notes:
         | 
| 78 81 | 
             
                  #   * see `#modify_keys_with()` for handling first-level keys
         | 
| 79 82 | 
             
                  #   * see `#pass_the_buck()` for the way nested structures are handled
         | 
| 80 83 | 
             
                  #   * case for different types taken from _MultiXML_ (multi_xml.rb)
         | 
| @@ -117,29 +120,29 @@ module Smash | |
| 117 120 | 
             
                  end
         | 
| 118 121 |  | 
| 119 122 | 
             
                  # Gets the path from the environment and sets @log_file using the path
         | 
| 120 | 
            -
                  #  | 
| 123 | 
            +
                  # Returns @log_file path <String>
         | 
| 121 124 | 
             
                  def log_file
         | 
| 122 125 | 
             
                    @log_file ||= zfind('LOG_FILE')
         | 
| 123 126 | 
             
                  end
         | 
| 124 127 |  | 
| 125 | 
            -
                  #  | 
| 128 | 
            +
                  # Returns An instance of Logger, cached as @logger
         | 
| 126 129 | 
             
                  def logger
         | 
| 127 130 | 
             
                    @logger ||= create_logger
         | 
| 128 131 | 
             
                  end
         | 
| 129 132 |  | 
| 130 133 | 
             
                  # Allows you to modify all first-level keys with a block that you pass.
         | 
| 131 134 | 
             
                  # If no block is passed, a copy is returned.
         | 
| 132 | 
            -
                  #  | 
| 135 | 
            +
                  # Parameters
         | 
| 133 136 | 
             
                  #   * params Hash|Array
         | 
| 134 137 | 
             
                  # === @&block (optional)
         | 
| 135 138 | 
             
                  #   * should modify the key and return that value so it can be used in the copy
         | 
| 136 | 
            -
                  #  | 
| 139 | 
            +
                  # Returns
         | 
| 137 140 | 
             
                  #   * a copy of the given Array or Hash, with all Hash keys modified
         | 
| 138 141 | 
             
                  # === Sample use:
         | 
| 139 142 | 
             
                  #   hash = { 'foo' => 'v1', 'bar' => { fleep: { 'florp' => 'yo' } } }
         | 
| 140 143 | 
             
                  #   modify_keys_with(hash) { |k| k.to_sym }
         | 
| 141 144 | 
             
                  #   # => { :foo => 'v1', :bar => { fleep: { 'florp' => 'yo' } } }
         | 
| 142 | 
            -
                  #  | 
| 145 | 
            +
                  # Notes:
         | 
| 143 146 | 
             
                  #   * see `#deep_modify_keys_with()` for handling nested keys
         | 
| 144 147 | 
             
                  #   * case for different types taken from _MultiXML_ (multi_xml.rb)
         | 
| 145 148 | 
             
                  def modify_keys_with(params)
         | 
| @@ -155,7 +158,7 @@ module Smash | |
| 155 158 | 
             
                  # until another bit of logic does what it's supposed to, kind of like
         | 
| 156 159 | 
             
                  # continuing to poll something and doing something when a package is ready
         | 
| 157 160 | 
             
                  # to be taken and processed.
         | 
| 158 | 
            -
                  #  | 
| 161 | 
            +
                  # Parameters
         | 
| 159 162 | 
             
                  #   * [allowed_attempts] or Infinity(default) <Number>: The number of times
         | 
| 160 163 | 
             
                  #       the loop should be allowed to...well, loop, before a failed retry occurs.
         | 
| 161 164 | 
             
                  #   * &test <Block>: A predicate method or block of code that is callable
         | 
| @@ -175,9 +178,9 @@ module Smash | |
| 175 178 | 
             
                  end
         | 
| 176 179 |  | 
| 177 180 | 
             
                  # Gives the path from the project root to lib/tasks[/#{file}.rb]
         | 
| 178 | 
            -
                  #  | 
| 181 | 
            +
                  # Parameters
         | 
| 179 182 | 
             
                  #   * [file] <String>: name of a file
         | 
| 180 | 
            -
                  #  | 
| 183 | 
            +
                  # Returns
         | 
| 181 184 | 
             
                  #   * path[/file] <String>
         | 
| 182 185 | 
             
                  #   * If a `file` is given, it will have a '.rb' file extension
         | 
| 183 186 | 
             
                  #   * If no `file` is given, it will return the `#task_require_path`
         | 
| @@ -187,7 +190,7 @@ module Smash | |
| 187 190 | 
             
                  end
         | 
| 188 191 |  | 
| 189 192 | 
             
                  # Gives the path from the project root to lib/tasks[/file]
         | 
| 190 | 
            -
                  #  | 
| 193 | 
            +
                  # Parameters String (optional)
         | 
| 191 194 | 
             
                  #   * file_name name of a file
         | 
| 192 195 | 
             
                  # ===  @returns:
         | 
| 193 196 | 
             
                  #   * path[/file] String
         | 
| @@ -198,8 +201,8 @@ module Smash | |
| 198 201 | 
             
                  end
         | 
| 199 202 |  | 
| 200 203 | 
             
                  # Change strings into camelCase
         | 
| 201 | 
            -
                  #  | 
| 202 | 
            -
                  #  | 
| 204 | 
            +
                  # Parameters var String
         | 
| 205 | 
            +
                  # Returns String
         | 
| 203 206 | 
             
                  #     * givenString
         | 
| 204 207 | 
             
                  def to_camel(var)
         | 
| 205 208 | 
             
                    var = var.to_s unless var.kind_of? String
         | 
| @@ -209,8 +212,8 @@ module Smash | |
| 209 212 | 
             
                  end
         | 
| 210 213 |  | 
| 211 214 | 
             
                  # Change strings hyphen-delimited-string
         | 
| 212 | 
            -
                  #  | 
| 213 | 
            -
                  #  | 
| 215 | 
            +
                  # Parameters var String
         | 
| 216 | 
            +
                  # Returns String
         | 
| 214 217 | 
             
                  #     * given-string
         | 
| 215 218 | 
             
                  def to_hyph(var)
         | 
| 216 219 | 
             
                    var = var.to_s unless var.kind_of? String
         | 
| @@ -225,8 +228,8 @@ module Smash | |
| 225 228 | 
             
                  end
         | 
| 226 229 |  | 
| 227 230 | 
             
                  # Change strings into snake_case and add '@' at the front
         | 
| 228 | 
            -
                  #  | 
| 229 | 
            -
                  #  | 
| 231 | 
            +
                  # Parameters var String
         | 
| 232 | 
            +
                  # Returns String
         | 
| 230 233 | 
             
                  #     * @given_string
         | 
| 231 234 | 
             
                  def to_i_var(var)
         | 
| 232 235 | 
             
                    var = var.to_s unless var.kind_of? String
         | 
| @@ -234,8 +237,8 @@ module Smash | |
| 234 237 | 
             
                  end
         | 
| 235 238 |  | 
| 236 239 | 
             
                  # Change strings into PascalCase
         | 
| 237 | 
            -
                  #  | 
| 238 | 
            -
                  #  | 
| 240 | 
            +
                  # Parameters var String
         | 
| 241 | 
            +
                  # Returns String
         | 
| 239 242 | 
             
                  #     * givenString
         | 
| 240 243 | 
             
                  def to_pascal(var)
         | 
| 241 244 | 
             
                    var = var.to_s unless var.kind_of? String
         | 
| @@ -243,8 +246,8 @@ module Smash | |
| 243 246 | 
             
                  end
         | 
| 244 247 |  | 
| 245 248 | 
             
                  # Change strings into a ruby_file_name with extension
         | 
| 246 | 
            -
                  #  | 
| 247 | 
            -
                  #  | 
| 249 | 
            +
                  # Parameters var String
         | 
| 250 | 
            +
                  # Returns String
         | 
| 248 251 | 
             
                  #     * given_string.rb
         | 
| 249 252 | 
             
                  #     * includes ruby file extension
         | 
| 250 253 | 
             
                  #     * see #to_snake()
         | 
| @@ -253,8 +256,8 @@ module Smash | |
| 253 256 | 
             
                  end
         | 
| 254 257 |  | 
| 255 258 | 
             
                  # Change strings into snake_case
         | 
| 256 | 
            -
                  #  | 
| 257 | 
            -
                  #  | 
| 259 | 
            +
                  # Parameters var String
         | 
| 260 | 
            +
                  # Returns String
         | 
| 258 261 | 
             
                  #     * given_string
         | 
| 259 262 | 
             
                  #     * will not have file extensions
         | 
| 260 263 | 
             
                  #     * see #to_ruby_file_name()
         | 
| @@ -271,9 +274,9 @@ module Smash | |
| 271 274 |  | 
| 272 275 | 
             
                  # This method provides a default overrideable message body for things like
         | 
| 273 276 | 
             
                  # basic status updates.
         | 
| 274 | 
            -
                  #  | 
| 277 | 
            +
                  # Parameters Hash
         | 
| 275 278 | 
             
                  #   - instanceId:
         | 
| 276 | 
            -
                  #  | 
| 279 | 
            +
                  # Notes:
         | 
| 277 280 | 
             
                  #   - camel casing is used on the keys because most other languages prefer
         | 
| 278 281 | 
             
                  #   that and it's not a huge problem in ruby.  Besides, there's some other
         | 
| 279 282 | 
             
                  #   handy methods in this module to get you through those issues, like
         | 
    
        data/lib/cloud_powers/node.rb
    CHANGED
    
    | @@ -11,7 +11,7 @@ module Smash | |
| 11 11 | 
             
                  include Smash::CloudPowers::SelfAwareness
         | 
| 12 12 | 
             
                  include Smash::CloudPowers::Zenv
         | 
| 13 13 | 
             
                  # These are sensible defaults that can be overriden by providing a Hash as a param.
         | 
| 14 | 
            -
                  #  | 
| 14 | 
            +
                  # Parameters [opts <Hash>]
         | 
| 15 15 | 
             
                  #   the opts Hash should have values that should be used instead of the given
         | 
| 16 16 | 
             
                  #   configuration.
         | 
| 17 17 | 
             
                  def node_config(opts = {})
         | 
| @@ -36,7 +36,7 @@ module Smash | |
| 36 36 | 
             
                  # configuration for the #run_instances method by using the opts hash that was
         | 
| 37 37 | 
             
                  # provided as a parameter.
         | 
| 38 38 | 
             
                  #
         | 
| 39 | 
            -
                  #  | 
| 39 | 
            +
                  # Parameters opts Hash (optional)
         | 
| 40 40 | 
             
                  #   an optional instance configuration hash can be passed, which will override
         | 
| 41 41 | 
             
                  #   the values in the default configuration returned by #instance_config()
         | 
| 42 42 | 
             
                  def spin_up_neurons(opts = {})
         | 
| @@ -17,7 +17,7 @@ module Smash | |
| 17 17 |  | 
| 18 18 | 
             
                  # Gets the instance time or the time it was called and as seconds from
         | 
| 19 19 | 
             
                  # epoch
         | 
| 20 | 
            -
                  #  | 
| 20 | 
            +
                  # Returns Integer
         | 
| 21 21 | 
             
                  # TODO: use time codes
         | 
| 22 22 | 
             
                  def boot_time
         | 
| 23 23 | 
             
                    begin
         | 
| @@ -68,16 +68,18 @@ module Smash | |
| 68 68 | 
             
                  end
         | 
| 69 69 |  | 
| 70 70 | 
             
                  # Assures there is always a valid instance id because many other Aws calls require it
         | 
| 71 | 
            -
                  #  | 
| 71 | 
            +
                  # Returns String
         | 
| 72 72 | 
             
                  def instance_id
         | 
| 73 73 | 
             
                    @instance_id ||= metadata_request('instance_id')
         | 
| 74 74 | 
             
                  end
         | 
| 75 75 |  | 
| 76 76 | 
             
                  # Gets and sets the public hostname of the instance
         | 
| 77 | 
            -
                  #  | 
| 78 | 
            -
                  # | 
| 79 | 
            -
                  # | 
| 80 | 
            -
                  # | 
| 77 | 
            +
                  # Returns
         | 
| 78 | 
            +
                  #   +String+
         | 
| 79 | 
            +
                  # Notes
         | 
| 80 | 
            +
                  # When this is being called from somewhere other than an Aws instance,
         | 
| 81 | 
            +
                  # a hardcoded example URL is returned
         | 
| 82 | 
            +
                  # because of the way instance metadata is retrieved
         | 
| 81 83 | 
             
                  def instance_url
         | 
| 82 84 | 
             
                    @instance_url ||= unless zfind('TESTING')
         | 
| 83 85 | 
             
                      hostname_uri = 'http://169.254.169.254/latest/meta-data/public-hostname'
         | 
| @@ -90,8 +92,13 @@ module Smash | |
| 90 92 | 
             
                  # Makes the http request to self/meta-data to get all the metadata keys or,
         | 
| 91 93 | 
             
                  # if a key is given, the method makes the http request to get that
         | 
| 92 94 | 
             
                  # particular key from the metadata
         | 
| 93 | 
            -
                  # | 
| 94 | 
            -
                  #  | 
| 95 | 
            +
                  #
         | 
| 96 | 
            +
                  # Parameters
         | 
| 97 | 
            +
                  # * <tt>key</tt> - +String+ (optional)
         | 
| 98 | 
            +
                  #
         | 
| 99 | 
            +
                  # === Returns
         | 
| 100 | 
            +
                  # * +Array+ if key is blank
         | 
| 101 | 
            +
                  # * +String+ if key is given
         | 
| 95 102 | 
             
                  def metadata_request(key = '')
         | 
| 96 103 | 
             
                    key = to_hyph(key)
         | 
| 97 104 | 
             
                    begin
         | 
| @@ -110,7 +117,7 @@ module Smash | |
| 110 117 | 
             
                  end
         | 
| 111 118 |  | 
| 112 119 | 
             
                  # Return the time since boot_time
         | 
| 113 | 
            -
                  #  | 
| 120 | 
            +
                  # Returns Integer
         | 
| 114 121 | 
             
                  # Notes:
         | 
| 115 122 | 
             
                  # * TODO: refactor to use valid time stamps for better tracking.
         | 
| 116 123 | 
             
                  # * reason -> separate regions or OSs etc.
         | 
| @@ -131,9 +138,9 @@ module Smash | |
| 131 138 | 
             
                  end
         | 
| 132 139 |  | 
| 133 140 | 
             
                  # Get the instance status.
         | 
| 134 | 
            -
                  #  | 
| 141 | 
            +
                  # Parameters id String (optional)
         | 
| 135 142 | 
             
                  #     * if no id is given, self-instance ID is returned
         | 
| 136 | 
            -
                  #  | 
| 143 | 
            +
                  # Returns String
         | 
| 137 144 | 
             
                  def status(id = @instance_id)
         | 
| 138 145 | 
             
                    begin
         | 
| 139 146 | 
             
                      ec2.describe_instances(dry_run: zfind('TESTING'), instance_ids: [id]).
         | 
| @@ -11,11 +11,17 @@ module Smash | |
| 11 11 | 
             
                      include Smash::CloudPowers::Zenv
         | 
| 12 12 |  | 
| 13 13 | 
             
                      # Prefers the given arn but it can make a best guess if none is given
         | 
| 14 | 
            +
                      #
         | 
| 15 | 
            +
                      # Returns
         | 
| 16 | 
            +
                      # arn +String+ - arn for this resource
         | 
| 14 17 | 
             
                      def arn
         | 
| 15 18 | 
             
                        set_arn || "arn:aws:sns:#{zfind(:region)}:#{zfind(:accound_number)}:#{set_name}"
         | 
| 16 19 | 
             
                      end
         | 
| 17 20 |  | 
| 18 21 | 
             
                      # Prefers the given name but it can parse the arn to find one
         | 
| 22 | 
            +
                      #
         | 
| 23 | 
            +
                      # Returns
         | 
| 24 | 
            +
                      # name +String+ - name for this resource
         | 
| 19 25 | 
             
                      def name
         | 
| 20 26 | 
             
                        set_name || set_arn.split(':').last
         | 
| 21 27 | 
             
                      end
         | 
| @@ -23,26 +29,38 @@ module Smash | |
| 23 29 | 
             
                    #################
         | 
| 24 30 |  | 
| 25 31 | 
             
                    # Creates a connection point for 1..N nodes to create a connection with the Broadcast
         | 
| 26 | 
            -
                    # | 
| 27 | 
            -
                    # | 
| 28 | 
            -
                    #  | 
| 32 | 
            +
                    #
         | 
| 33 | 
            +
                    # Parameters
         | 
| 34 | 
            +
                    # * channel +String+
         | 
| 35 | 
            +
                    #
         | 
| 36 | 
            +
                    # Notes
         | 
| 37 | 
            +
                    # This method is not implemented yet (V 0.2.7)
         | 
| 38 | 
            +
                    def create_distributor(channel)
         | 
| 39 | 
            +
                      sns.create_application_platform()
         | 
| 40 | 
            +
                    end
         | 
| 29 41 |  | 
| 30 42 | 
             
                    # Creates a point to connect to for information about a given topic
         | 
| 31 | 
            -
                    # | 
| 32 | 
            -
                    #  | 
| 43 | 
            +
                    #
         | 
| 44 | 
            +
                    # Parameters
         | 
| 45 | 
            +
                    # * name +String+ - the name of the Channel/Topic to be created
         | 
| 46 | 
            +
                    #
         | 
| 47 | 
            +
                    # Returns
         | 
| 48 | 
            +
                    # +Broadcast::Channel+ - representing the created channel
         | 
| 33 49 | 
             
                    def create_channel!(name)
         | 
| 34 50 | 
             
                      resp = sns.create_topic(name: name)
         | 
| 35 51 | 
             
                      Channel.new(nil, resp.topic_arn)
         | 
| 36 52 | 
             
                    end
         | 
| 37 53 |  | 
| 38 54 | 
             
                    # Deletes a topic from SNS-land
         | 
| 39 | 
            -
                    # | 
| 55 | 
            +
                    #
         | 
| 56 | 
            +
                    # Parameters
         | 
| 57 | 
            +
                    # * channel <Broadcast::Channel>
         | 
| 40 58 | 
             
                    def delete_channel!(channel)
         | 
| 41 59 | 
             
                      sns.delete_topic(topic_arn: channel.arn)
         | 
| 42 60 | 
             
                    end
         | 
| 43 61 |  | 
| 44 62 | 
             
                    # Creates a connection to the Broadcast so that new messages will be picked up
         | 
| 45 | 
            -
                    #  | 
| 63 | 
            +
                    # Parameters channel <Broadcast::Channel>
         | 
| 46 64 | 
             
                    def listen_on(channel)
         | 
| 47 65 | 
             
                      sns.subscribe(
         | 
| 48 66 | 
             
                        topic_arn:    channel.arn,
         | 
| @@ -52,7 +70,7 @@ module Smash | |
| 52 70 | 
             
                    end
         | 
| 53 71 |  | 
| 54 72 | 
             
                    # Lists the created topics in SNS.
         | 
| 55 | 
            -
                    #  | 
| 73 | 
            +
                    # Returns results <Array
         | 
| 56 74 | 
             
                    def real_channels
         | 
| 57 75 | 
             
                      results = []
         | 
| 58 76 | 
             
                      next_token = ''
         | 
| @@ -66,7 +84,7 @@ module Smash | |
| 66 84 | 
             
                    end
         | 
| 67 85 |  | 
| 68 86 | 
             
                    # Send a message to a Channel using SNS#publish
         | 
| 69 | 
            -
                    #  | 
| 87 | 
            +
                    # Parameters [opts <Hash>]:
         | 
| 70 88 | 
             
                    #   this includes all the keys AWS uses but for now it only has defaults
         | 
| 71 89 | 
             
                    #   for topic_arn and the message
         | 
| 72 90 | 
             
                    def send_broadcast(opts = {})
         |