jdc 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2013 JingDong, All Rights Reserved
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
21
+ This software downloads additional open source software components upon install
22
+ that are distributed under separate terms and conditions. Please see the license
23
+ information provided in the individual software components for more information.
24
+
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ #JDC
2
+
3
+ The JingDong Cloud CLI. This is the command line interface to JingDong's Application Platform
4
+
5
+ _Copyright 2013, JingDong. Please see the License file.
6
+
7
+ ##Installation
8
+
9
+ You can install the JDC for Ruby with rubygems
10
+
11
+ $gem install jdc
12
+ $jdc -v
13
+ jdc 0.1.0
14
+
15
+ If you are using Bundler, we recommend that you express a major version dependency:
16
+
17
+ gem 'jdc', '~> 0.1.0'
18
+
19
+ ##Development
20
+
21
+ $git clone https://github.com/jingdong-app-engine/jdc.git
22
+ $cd jdc
23
+ $bundle install
24
+
25
+ ##Basic Configuration
26
+
27
+ You need to provide your JingDong security credentials
28
+
29
+ You can also specify these values via `ENV`:
30
+
31
+ export ACCESS_KEY_ID='...'
32
+ export SECRET_KEY='...'
33
+
34
+ ##Usage
35
+
36
+ Usage: jdc [options] command [<args>] [command_options]
37
+ Try 'jdc help [command]' or 'jdc help options' for more information.
38
+
39
+ Currently available jdc commands are:
40
+
41
+ Getting Started
42
+ target [url] Reports current target or sets a new target
43
+ info System and account information
44
+
45
+ Applications
46
+ user Display current user account information
47
+ apps List deployed applications
48
+
49
+ Application Creation
50
+ push [appname] Create, push, map, and start a new application
51
+ push [appname] --path Push application from specified path
52
+ push [appname] --url Set the url for the application
53
+ push [appname] --instances <N> Set the expected number <N> of instances
54
+ push [appname] --mem M Set the memory reservation for the application
55
+ push [appname] --runtime RUNTIME Set the runtime to use for the application
56
+ push [appname] --debug [MODE] Push application and start in a debug mode
57
+ push [appname] --no-start Do not auto-start the application
58
+
59
+ Application Operations
60
+ start <appname> [--debug [MODE]] Start the application
61
+ stop <appname> Stop the application
62
+ restart <appname> [--debug [MODE]] Restart the application
63
+ delete <appname> Delete the application
64
+
65
+ Application Updates
66
+ update <appname> [--path,--debug [MODE]] Update the application bits
67
+ mem <appname> [memsize] Update the memory reservation for an application
68
+ map <appname> <url> Register the application to the url
69
+ unmap <appname> <url> Unregister the application from the url
70
+ instances <appname> <num|delta> Scale the application instances up or down
71
+
72
+ Application Information
73
+ crashes <appname> List recent application crashes
74
+ crashlogs <appname> Display log information for crashed applications
75
+ logs <appname> [--all] Display log information for the application
76
+ files <appname> [path] [--all] Display directory listing or file download for [path]
77
+ stats <appname> Display resource usage for the application
78
+ instances <appname> List application instances
79
+
80
+ Application Environment
81
+ env <appname> List application environment variables
82
+ env-add <appname> <variable[=]value> Add an environment variable to an application
83
+ env-del <appname> <variable> Delete an environment variable to an application
84
+
85
+ System
86
+ runtimes Display the supported runtimes of the target system
87
+ frameworks Display the recognized frameworks of the target system
88
+
89
+ Misc
90
+ aliases List aliases
91
+ alias <alias[=]command> Create an alias for a command
92
+ unalias <alias> Remove an alias
93
+
94
+ Help
95
+ help [command] Get general help or help on a specific command
96
+ help options Get help on available options
97
+
98
+ ##Simple Story (for Ruby apps)
99
+
100
+ jdc target api.jd-app.com
101
+ jdc push ruby_app
102
+
data/bin/jdc ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/cli', __FILE__)
4
+
5
+ JDC::Cli::Runner.run(ARGV.dup)
6
+
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2009-2011 VMware, Inc.
3
+ $:.unshift(File.dirname(__FILE__) + '/lib')
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+
8
+ require 'caldecott'
9
+ require 'sinatra'
10
+ require 'json'
11
+ require 'eventmachine'
12
+
13
+ port = ENV['JDC_APP_PORT']
14
+ port ||= 8081
15
+
16
+ # add vcap specific stuff to Caldecott
17
+ class VcapHttpTunnel < Caldecott::Server::HttpTunnel
18
+ get '/info' do
19
+ { "version" => '0.0.4' }.to_json
20
+ end
21
+
22
+ def self.get_tunnels
23
+ super
24
+ end
25
+
26
+ get '/services' do
27
+ services_env = ENV['JDC_SERVICES']
28
+ return "no services env" if services_env.nil? or services_env.empty?
29
+ services_env
30
+ end
31
+
32
+ get '/services/:service' do |service_name|
33
+ services_env = ENV['JDC_SERVICES']
34
+ not_found if services_env.nil?
35
+
36
+ services = JSON.parse(services_env)
37
+ service = services.find { |s| s["name"] == service_name }
38
+ not_found if service.nil?
39
+ service["options"].to_json
40
+ end
41
+ end
42
+
43
+ VcapHttpTunnel.run!(:port => port, :auth_token => ENV["CALDECOTT_AUTH"])
@@ -0,0 +1,17 @@
1
+ redis:
2
+ redis-cli: -h ${host} -p ${port} -a ${password}
3
+
4
+ mysql:
5
+ mysql: --protocol=TCP --host=${host} --port=${port} --user=${user} --password=${password} ${name}
6
+ mysqldump: --protocol=TCP --host=${host} --port=${port} --user=${user} --password=${password} ${name} > ${Output file}
7
+
8
+ mongodb:
9
+ mongo: --host ${host} --port ${port} -u ${user} -p ${password} ${name}
10
+ mongodump: --host ${host} --port ${port} -u ${user} -p ${password} --db ${name}
11
+ mongorestore: --host ${host} --port ${port} -u ${user} -p ${password} --db ${name} ${Directory or filename to restore from}
12
+
13
+ postgresql:
14
+ psql:
15
+ command: -h ${host} -p ${port} -d ${name} -U ${user} -w
16
+ environment:
17
+ - PGPASSWORD='${password}'
@@ -0,0 +1,22 @@
1
+ darwin:
2
+ vmrun:
3
+ - "/Applications/VMware Fusion.app/Contents/Library/"
4
+ - "/Applications/Fusion.app/Contents/Library/"
5
+ vmx:
6
+ - "~/Documents/Virtual Machines.localized/"
7
+ - "~/Documents/Virtual Machines/"
8
+ - "~/Desktop/"
9
+
10
+ linux:
11
+ vmrun:
12
+ - "/usr/bin/"
13
+ vmx:
14
+ - "~/"
15
+
16
+ windows:
17
+ vmrun:
18
+ - "c:\\Program Files (x86)\\"
19
+ - "c:\\Program Files\\"
20
+ vmx:
21
+ - "~\\Documents\\"
22
+ - "~\\Desktop\\"
@@ -0,0 +1,20 @@
1
+ #!/var/vcap/bosh/bin/ruby
2
+ require 'socket'
3
+
4
+ A_ROOT_SERVER = '198.41.0.4'
5
+
6
+ begin
7
+ retries ||= 0
8
+ route ||= A_ROOT_SERVER
9
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
10
+ ip_address = UDPSocket.open {|s| s.connect(route, 1); s.addr.last }
11
+ rescue Errno::ENETUNREACH
12
+ # happens on boot when dhcp hasn't completed when we get here
13
+ sleep 3
14
+ retries += 1
15
+ retry if retries < 10
16
+ ensure
17
+ Socket.do_not_reverse_lookup = orig
18
+ end
19
+
20
+ File.open("/tmp/ip.txt", 'w') { |file| file.write(ip_address) }
@@ -0,0 +1,58 @@
1
+ module JDC::Cli::Command
2
+
3
+ class Admin < Base
4
+
5
+ def list_users
6
+ users = client.users
7
+ users.sort! {|a, b| a[:email] <=> b[:email] }
8
+ return display JSON.pretty_generate(users || []) if @options[:json]
9
+
10
+ display "\n"
11
+ return display "No Users" if users.nil? || users.empty?
12
+
13
+ users_table = table do |t|
14
+ t.headings = 'Email', 'Admin', 'Apps'
15
+ users.each do |user|
16
+ t << [user[:email], user[:admin], user[:apps].map {|x| x[:name]}.join(', ')]
17
+ end
18
+ end
19
+ display users_table
20
+ end
21
+
22
+ alias :users :list_users
23
+
24
+ def delete_user(user_email)
25
+ # Check to make sure all apps and services are deleted before deleting the user
26
+ # implicit proxying
27
+
28
+ client.proxy_for(user_email)
29
+ @options[:proxy] = user_email
30
+ apps = client.apps
31
+
32
+ if (apps && !apps.empty?)
33
+ unless no_prompt
34
+ proceed = ask(
35
+ "\nDeployed applications and associated services will be DELETED, continue?",
36
+ :default => false
37
+ )
38
+ err "Aborted" unless proceed
39
+ end
40
+ cmd = Apps.new(@options.merge({ :force => true }))
41
+ apps.each { |app| cmd.delete(app[:name]) }
42
+ end
43
+
44
+ services = client.services
45
+ if (services && !services.empty?)
46
+ cmd = Services.new(@options)
47
+ services.each { |s| cmd.delete_service(s[:name])}
48
+ end
49
+
50
+ display 'Deleting User: ', false
51
+ client.proxy = nil
52
+ client.delete_user(user_email)
53
+ display 'OK'.green
54
+ end
55
+
56
+ end
57
+
58
+ end