lib/vmc/client.rb in af-0.3.18.3 vs lib/vmc/client.rb in af-0.3.18.4

- old
+ new

@@ -20,11 +20,11 @@ def self.version VMC::VERSION end attr_reader :target, :host, :user, :proxy, :auth_token - attr_accessor :trace + attr_accessor :trace, :infra # Error codes VMC_HTTP_ERROR_CODES = [ 400, 500 ] HTTP_TIMEOUT = ENV['TIMEOUT'] ? ENV['TIMEOUT'].to_i : 10*60 @@ -245,13 +245,17 @@ # Send in a resources manifest array to the system to have # it check what is needed to actually send. Returns array # indicating what is needed. This returned manifest should be # sent in with the upload if resources were removed. # E.g. [{:sha1 => xxx, :size => xxx, :fn => filename}] - def check_resources(resources) + def check_resources(resources,infra=nil) check_login_status - status, body, headers = json_post(VMC::RESOURCES_PATH, resources) + url = VMC::RESOURCES_PATH + unless infra.nil? + url += "?infra=#{infra}" + end + status, body, headers = json_post(url, resources) json_parse(body) end ###################################################### # Validation Helpers @@ -339,15 +343,43 @@ URI.encode x.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") }.join("/") end ###################################################### - + # Infrastructure + ###################################################### + + def infras + json_get(path(VMC::GLOBAL_INFRAS_PATH)) + rescue + [] + end + def infra_supported? - # FIXME should get this from proxy - target.match /^https?:\/\/api.appfog.com$/ + !infras.empty? end - + + def base_for_infra(name) + info = infras.detect { |i| i[:infra] == name } + info ? info[:base] : "aws.af.cm" + end + + def infra_valid?(name) + infras.detect { |i| i[:infra] == name } + end + + def infra_descriptions + infras.map { |i| i[:description] } + end + + def infra_name_for_description(desc) + info = infras.detect { |i| i[:description] == desc } + info ? info[:infra] : "" + end + + def suggest_url(infra=nil) + @suggest_url ||= base_for_infra(infra || @infra) + end private def path(*args, &blk)