Module: RightScale::Api::Taggable
- Included in:
- Deployment, Ec2EbsSnapshot, Ec2EbsVolume, Ec2ServerArray, Instance, McTaggable, Server, ServerEc2EbsVolume, ServerTemplate
- Defined in:
- lib/rest_connection/rightscale/rightscale_api_taggable.rb
Instance Method Summary collapse
- #add_tags(*args) ⇒ Object
- #clear_tags(namespace = nil) ⇒ Object
- #get_info_tags(*tag_keys) ⇒ Object
- #get_tags_by_namespace(namespace) ⇒ Object
- #remove_info_tags(*tag_keys) ⇒ Object
- #remove_tags(*args) ⇒ Object
- #remove_tags_by_namespace(namespace, *tag_keys) ⇒ Object
- #set_info_tags(hsh = {}) ⇒ Object
- #set_tags_by_namespace(namespace, hsh = {}) ⇒ Object
- #set_tags_to(*args) ⇒ Object
- #tags(reload = false) ⇒ Object
Instance Method Details
#add_tags(*args) ⇒ Object
27 28 29 30 31 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 27 def (*args) return false if args.empty? Tag.set(self.href, args.uniq) self.(true) end |
#clear_tags(namespace = nil) ⇒ Object
107 108 109 110 111 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 107 def (namespace = nil) tag_ary = self.(true) tag_ary = tag_ary.select { |tag| tag.start_with?("#{namespace}:") } if namespace self.(*tag_ary) end |
#get_info_tags(*tag_keys) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 55 def (*tag_keys) = ("info") .each { |resource,hsh| hsh.reject! { |key,value| rej = false rej = !tag_keys.include?(key) unless tag_keys.empty? rej } } return end |
#get_tags_by_namespace(namespace) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 86 def (namespace) ret = {} = {"self" => self.(true)} .each { |res,ary| ret[res] ||= {} ary.each { |tag| next unless tag.start_with?("#{namespace}:") key = tag.split("=").first.split(":")[1..-1].join(":") value = tag.split(":")[1..-1].join(":").split("=")[1..-1].join("=") ret[res][key] = value } } return ret end |
#remove_info_tags(*tag_keys) ⇒ Object
47 48 49 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 47 def (*tag_keys) ("info", *tag_keys) end |
#remove_tags(*args) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 33 def (*args) return false if args.empty? Tag.unset(self.href, args.uniq) @params["tags"] -= args self.(true) end |
#remove_tags_by_namespace(namespace, *tag_keys) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 67 def (namespace, *tag_keys) = [] = (namespace) .each { |res,hsh| hsh.each { |k,v| << "#{namespace}:#{k}=#{v}" if tag_keys.include?(k) } } self.(*) end |
#set_info_tags(hsh = {}) ⇒ Object
51 52 53 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 51 def (hsh={}) ("info", hsh) end |
#set_tags_by_namespace(namespace, hsh = {}) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 78 def (namespace, hsh={}) keys_to_change = [] = [] hsh.each { |k,v| keys_to_change << k; << "#{namespace}:#{k}=#{v}" } self.(namespace, *keys_to_change) self.(*) end |
#set_tags_to(*args) ⇒ Object
101 102 103 104 105 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 101 def (*args) STDERR.puts "set_tags_to(...) is deprecated" self.("info") self.(*(args.uniq)) end |
#tags(reload = false) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rest_connection/rightscale/rightscale_api_taggable.rb', line 40 def (reload=false) @params["tags"] ||= [] @params["tags"].map! { |item| item.is_a?(Hash) ? item["name"] : item } @params["tags"].deep_merge!(Tag.search_by_href(self.href).map { |hsh| hsh["name"] }) if reload or @params["tags"].empty? @params["tags"] end |