lib/vmc/client.rb in af-0.3.18.2 vs lib/vmc/client.rb in af-0.3.18.3
- old
+ new
@@ -156,10 +156,21 @@
path = path.gsub('//', '/')
url = path(VMC::APPS_PATH, name, "instances", instance, "files", path)
_, body, headers = http_get(url)
body
end
+
+ def app_pull(name, dir)
+ check_login_status
+ url = path(VMC::APPS_PATH, name, "application")
+ status, body, headers = http_get(url,'application/octet-stream')
+ file = Tempfile.new(name)
+ file.write(body)
+ file.close
+ ::VMC::Cli::ZipUtil.unpack(file.path, dir)
+ file.unlink
+ end
######################################################
# Services
######################################################
@@ -206,11 +217,15 @@
http_delete(path(VMC::SERVICES_PATH, name))
end
def bind_service(service, appname)
check_login_status
+ svc = services.detect { |s| s[:name] == service }
app = app_info(appname)
+ if infra_supported? && ! infras_match?(app,svc)
+ raise TargetError, "Service #{service} and App #{appname} are not on the same infra"
+ end
services = app[:services] || []
app[:services] = services << service
update_app(appname, app)
end
@@ -323,10 +338,19 @@
path.flatten.collect { |x|
URI.encode x.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
}.join("/")
end
+ ######################################################
+
+ def infra_supported?
+ # FIXME should get this from proxy
+ target.match /^https?:\/\/api.appfog.com$/
+ end
+
+
+
private
def path(*args, &blk)
self.class.path(*args, &blk)
end
@@ -470,6 +494,10 @@
def check_login_status
raise AuthError unless @user || logged_in?
end
+ def infras_match?(o1,o2)
+ o1 && o2 && ( o1[:infra] == o2[:infra])
+ end
+
end