Skip to content

Commit

Permalink
add service import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
lhitchon committed Sep 19, 2012
1 parent 5439ee9 commit b78189d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
23 changes: 22 additions & 1 deletion lib/cli/commands/services.rb
Expand Up @@ -93,7 +93,28 @@ def clone_services(src_app, dest_app)
services.each { |service| bind_service_banner(service, dest_app, false) }
check_app_for_restart(dest_app)
end


def export_service(service)
display "Exporting data from '#{service}': ", false
export_info = client.export_service(service)
if export_info
display 'OK'.green
puts export_info[:uri]
else
err "Export data from '#{service}': failed"
end
end

def import_service(service,url)
display "Importing data into '#{service}': ", false
import_info = client.import_service(service,url)
if import_info
display 'OK'.green
else
err "Import data into '#{service}' failed"
end
end

def tunnel(service=nil, client_name=nil)
unless defined? Caldecott
display "To use `af tunnel', you must first install Caldecott:"
Expand Down
8 changes: 8 additions & 0 deletions lib/cli/runner.rb
Expand Up @@ -374,6 +374,14 @@ def parse_command!
usage('af clone-services <src-app> <dest-app>')
set_cmd(:services, :clone_services, 2)

when 'export-service'
usage('af export-service <service-name>')
set_cmd(:services, :export_service, 1)

when 'import-service'
usage('af import-service <service-name> <url>')
set_cmd(:services, :import_service, 2)

when 'aliases'
usage('af aliases')
set_cmd(:misc, :aliases)
Expand Down
4 changes: 3 additions & 1 deletion lib/cli/usage.rb
Expand Up @@ -75,13 +75,15 @@ def command_usage
Services
services Lists of services available and provisioned
create-service <service> [--name,--bind] Create a provisioned service
create-service <service> --infra Create a provisioned service on a specified infrastructure
create-service <service> --infra Create a provisioned service on a specified infrastructure
create-service <service> <name> Create a provisioned service and assign it <name>
create-service <service> <name> <app> Create a provisioned service and assign it <name>, and bind to <app>
delete-service [servicename] Delete a provisioned service
bind-service <servicename> <appname> Bind a service to an application
unbind-service <servicename> <appname> Unbind service from the application
clone-services <src-app> <dest-app> Clone service bindings from <src-app> application to <dest-app>
export-service <service> Export the data from a service
import-service <service> <url> Import data into a service
tunnel <servicename> [--port] Create a local tunnel to a service
tunnel <servicename> <clientcmd> Create a local tunnel to a service and start a local client
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/version.rb
Expand Up @@ -2,6 +2,6 @@ module VMC
module Cli
# This version number is used as the RubyGem release version.
# The internal VMC version number is VMC::VERSION.
VERSION = '0.3.18.4'
VERSION = '0.3.18.5'
end
end
8 changes: 8 additions & 0 deletions lib/vmc/client.rb
Expand Up @@ -237,6 +237,14 @@ def unbind_service(service, appname)
app[:services] = services
update_app(appname, app)
end

def export_service(service)
json_get(path(VMC::SERVICE_EXPORT_PATH, service))
end

def import_service(service,uri)
json_post(path(VMC::SERVICE_IMPORT_PATH, service),{uri:uri})
end

######################################################
# Resources
Expand Down
4 changes: 4 additions & 0 deletions lib/vmc/const.rb
Expand Up @@ -19,5 +19,9 @@ module VMC
APPS_PATH = 'apps'
SERVICES_PATH = 'services'
USERS_PATH = 'users'

# Service paths
SERVICE_EXPORT_PATH = ['services','export']
SERVICE_IMPORT_PATH = ['services','import']

end

0 comments on commit b78189d

Please sign in to comment.