Class: CloudInteractor::Helper
- Inherits:
-
Object
- Object
- CloudInteractor::Helper
- Defined in:
- lib/cloud_interactor/helpers.rb
Instance Method Summary collapse
- #generic_destroy_parse(destroy_hash, identity, resource, mode = 'name') ⇒ Object
- #generic_list_call(identity, resource, output = true) ⇒ Object
- #generic_read_parse(args, identity, output = true, mode = 'name', search_key = 'name') ⇒ Object
-
#initialize(main_obj, classes, options = {}) ⇒ Helper
constructor
A new instance of Helper.
- #set_specific_identity(args, key_to_extract) ⇒ Object
Constructor Details
#initialize(main_obj, classes, options = {}) ⇒ Helper
Returns a new instance of Helper.
3 4 5 6 7 |
# File 'lib/cloud_interactor/helpers.rb', line 3 def initialize main_obj, classes, ={} @main_obj = main_obj = @classes = classes end |
Instance Method Details
#generic_destroy_parse(destroy_hash, identity, resource, mode = 'name') ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cloud_interactor/helpers.rb', line 52 def generic_destroy_parse destroy_hash, identity, resource, mode='name' puts("Queried #{ identity } #{ ap @main_obj["specific_#{ identity }"] }") if ['verbose'] raise "#{ identity.singularize } not found for #{ destroy_hash[mode] }" unless @main_obj["specific_#{ identity }"] if destroy_hash[mode].empty? || @main_obj["specific_#{ identity }"].last[mode] != destroy_hash[mode] #without this it will delete the first object in the list, this is obviously bad raise "Name mismatch on destroy! Expected #{ destroy_hash[mode] } and was going to destroy #{ @main_obj["specific_#{ identity }"].last[mode] }" end puts "Destroying #{ destroy_hash[mode] }..." specific_fog_object = @classes['auth'].auth_service(resource).instance_eval(identity).get @main_obj["specific_#{ identity }"].last['id'] @main_obj["#{ identity }_destroy_request"] = specific_fog_object.destroy puts "REMINDER! This destroy is not instant! It can take up to a few minutes for a #{ identity.singularize } to actually be fully destroyed!" end |
#generic_list_call(identity, resource, output = true) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/cloud_interactor/helpers.rb', line 16 def generic_list_call identity, resource, output=true puts "Returning list of #{ identity } for #{ @options['preferred_cloud'] }..." @main_obj[identity] = JSON.parse(@classes['auth'].auth_service(resource).instance_eval(identity).to_json) ap(@main_obj[identity]) if output && !['in_scaling'] end |
#generic_read_parse(args, identity, output = true, mode = 'name', search_key = 'name') ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cloud_interactor/helpers.rb', line 24 def generic_read_parse args, identity, output=true, mode='name', search_key='name' search_key = mode if mode != 'name' && search_key == 'name' specific_identity = set_specific_identity args, search_key @main_obj["specific_#{ identity }"] ||= [] @main_obj[identity].each do |identity_hash| if specific_identity.nil? puts("Query arguments \"#{ args }\" are not being mapped correctly for #{ identity.singularize } reads from method #{ caller[3][/`.*'/][1..-2] }! This read will return no objects.") break end next if identity_hash[mode] && !identity_hash[mode].include?(specific_identity) next if identity == 'servers' && identity_hash['state'] == 'DELETED' #FOR SOME REASON you will get status 'DELETED' items on reads sometimes for rackspace servers case identity when 'image' then @main_obj["specific_#{ identity }"] << identity_hash unless identity_hash[mode].include?(['virtualization_mode']) else @main_obj["specific_#{ identity }"] << identity_hash end ap(identity_hash) if output end puts("#{ specific_identity } not found in #{ identity }!") if @main_obj["specific_#{ identity }"].empty? end |
#set_specific_identity(args, key_to_extract) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/cloud_interactor/helpers.rb', line 9 def set_specific_identity args, key_to_extract case args.class.to_s when "Hash" then args[key_to_extract] when "String" then args end end |