acquia_toolbelt 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/.gitignore +7 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +7 -0
  4. data/CONTRIBUTING.md +11 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +55 -0
  7. data/Guardfile +5 -0
  8. data/LICENSE +19 -0
  9. data/README.md +149 -0
  10. data/Rakefile +1 -0
  11. data/acquia_toolbelt.gemspec +34 -0
  12. data/bin/acquia +9 -0
  13. data/lib/acquia_toolbelt/cli/api.rb +164 -0
  14. data/lib/acquia_toolbelt/cli/auth.rb +31 -0
  15. data/lib/acquia_toolbelt/cli/database.rb +237 -0
  16. data/lib/acquia_toolbelt/cli/deploy.rb +36 -0
  17. data/lib/acquia_toolbelt/cli/domain.rb +177 -0
  18. data/lib/acquia_toolbelt/cli/environment.rb +71 -0
  19. data/lib/acquia_toolbelt/cli/file.rb +31 -0
  20. data/lib/acquia_toolbelt/cli/server.rb +67 -0
  21. data/lib/acquia_toolbelt/cli/site.rb +28 -0
  22. data/lib/acquia_toolbelt/cli/ssh.rb +78 -0
  23. data/lib/acquia_toolbelt/cli/svn.rb +73 -0
  24. data/lib/acquia_toolbelt/cli/task.rb +74 -0
  25. data/lib/acquia_toolbelt/cli/ui.rb +44 -0
  26. data/lib/acquia_toolbelt/cli.rb +103 -0
  27. data/lib/acquia_toolbelt/error.rb +4 -0
  28. data/lib/acquia_toolbelt/thor.rb +95 -0
  29. data/lib/acquia_toolbelt/version.rb +3 -0
  30. data/lib/acquia_toolbelt.rb +4 -0
  31. data/lib/vendor/thor/CHANGELOG.md +139 -0
  32. data/lib/vendor/thor/Gemfile +20 -0
  33. data/lib/vendor/thor/LICENSE.md +20 -0
  34. data/lib/vendor/thor/README.md +35 -0
  35. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  36. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  37. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  38. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  39. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
  40. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  41. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  42. data/lib/vendor/thor/lib/thor/base.rb +654 -0
  43. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  44. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  45. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  46. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  47. data/lib/vendor/thor/lib/thor/error.rb +32 -0
  48. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  49. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  50. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  51. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  52. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  53. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  54. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  55. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  56. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  57. data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
  58. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  59. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  60. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  61. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  62. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  63. data/lib/vendor/thor/lib/thor.rb +474 -0
  64. data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
  65. data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
  66. data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
  67. data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
  68. data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
  69. data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
  70. data/lib/vendor/thor/spec/actions_spec.rb +331 -0
  71. data/lib/vendor/thor/spec/base_spec.rb +291 -0
  72. data/lib/vendor/thor/spec/command_spec.rb +80 -0
  73. data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
  74. data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
  75. data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
  76. data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
  77. data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
  78. data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
  79. data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
  80. data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
  81. data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  82. data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
  83. data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
  84. data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
  85. data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
  86. data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
  87. data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
  88. data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  89. data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
  90. data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
  91. data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
  92. data/lib/vendor/thor/spec/fixtures/path with spaces +0 -0
  93. data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
  94. data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
  95. data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
  96. data/lib/vendor/thor/spec/group_spec.rb +222 -0
  97. data/lib/vendor/thor/spec/helper.rb +67 -0
  98. data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
  99. data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
  100. data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
  101. data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
  102. data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
  103. data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
  104. data/lib/vendor/thor/spec/register_spec.rb +197 -0
  105. data/lib/vendor/thor/spec/runner_spec.rb +241 -0
  106. data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
  107. data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
  108. data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
  109. data/lib/vendor/thor/spec/shell_spec.rb +47 -0
  110. data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
  111. data/lib/vendor/thor/spec/thor_spec.rb +499 -0
  112. data/lib/vendor/thor/spec/util_spec.rb +196 -0
  113. data/lib/vendor/thor/thor.gemspec +24 -0
  114. data/script/release +50 -0
  115. data/script/setup_build +6 -0
  116. data/script/test +23 -0
  117. data/spec/auth_spec.rb +15 -0
  118. data/spec/cassettes/databases/all_databases.json +1 -0
  119. data/spec/cassettes/databases/copy_database_from_dev_to_stage.json +1 -0
  120. data/spec/cassettes/databases/create_a_database_backup.json +1 -0
  121. data/spec/cassettes/databases/create_a_new_database.json +1 -0
  122. data/spec/cassettes/databases/delete_a_database.json +1 -0
  123. data/spec/cassettes/databases/get_all_existing_databases.json +1 -0
  124. data/spec/cassettes/databases/list_all_database_backups.json +1 -0
  125. data/spec/cassettes/databases/view_database_instance_details.json +1 -0
  126. data/spec/cassettes/deploy/release_vcs_branch.json +1 -0
  127. data/spec/cassettes/domains/create_new_domain.json +1 -0
  128. data/spec/cassettes/domains/delete_a_domain.json +1 -0
  129. data/spec/cassettes/domains/get_all_existing_domains.json +1 -0
  130. data/spec/cassettes/domains/list_all_dev_domains.json +1 -0
  131. data/spec/cassettes/domains/move_from_dev_to_stage.json +1 -0
  132. data/spec/cassettes/domains/purge_varnish_cache.json +1 -0
  133. data/spec/cassettes/environments/all_environments.json +1 -0
  134. data/spec/cassettes/environments/disable_live_development.json +1 -0
  135. data/spec/cassettes/environments/enable_live_development.json +1 -0
  136. data/spec/cassettes/files/copy_from_dev_to_stage.json +1 -0
  137. data/spec/cassettes/servers/all_dev_servers.json +1 -0
  138. data/spec/cassettes/servers/all_prod_servers.json +1 -0
  139. data/spec/cassettes/sites/all_sites.json +1 -0
  140. data/spec/cassettes/ssh/all_sshkeys.json +1 -0
  141. data/spec/cassettes/svn/all_svnusers.json +1 -0
  142. data/spec/cassettes/tasks/all_tasks.json +1 -0
  143. data/spec/databases_spec.rb +78 -0
  144. data/spec/deploy_spec.rb +12 -0
  145. data/spec/domains_spec.rb +59 -0
  146. data/spec/environments_spec.rb +35 -0
  147. data/spec/files_spec.rb +11 -0
  148. data/spec/helper.rb +104 -0
  149. data/spec/servers_spec.rb +59 -0
  150. data/spec/sites_spec.rb +19 -0
  151. data/spec/ssh_spec.rb +19 -0
  152. data/spec/svn_spec.rb +11 -0
  153. data/spec/tasks_spec.rb +11 -0
  154. metadata +158 -4
@@ -0,0 +1,237 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Databases < AcquiaToolbelt::Thor
4
+ no_tasks do
5
+ # Internal: Build the database output.
6
+ #
7
+ # Output the database information exposing all the available fields and
8
+ # data to the end user.
9
+ #
10
+ # database - The name of the database you wish to fetch the information
11
+ # about.
12
+ #
13
+ # Returns multiple lines.
14
+ def output_database_instance(database)
15
+ ui.say "> Username: #{database["username"]}"
16
+ ui.say "> Password: #{database["password"]}"
17
+ ui.say "> Host: #{database["host"]}"
18
+ ui.say "> DB cluster: #{database["db_cluster"]}"
19
+ ui.say "> Instance name: #{database["instance_name"]}"
20
+ end
21
+ end
22
+
23
+ # Public: Add a database to the subscription.
24
+ #
25
+ # Returns a status message.
26
+ desc "add", "Add a database."
27
+ method_option :database, :type => :string, :aliases => %w(-d), :required => true,
28
+ :desc => "Name of the database to create."
29
+ def add
30
+ if options[:subscription]
31
+ subscription = options[:subscription]
32
+ else
33
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
34
+ end
35
+
36
+ database = options[:database]
37
+ add_database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs", "POST", :db => "#{database}"
38
+
39
+ puts "#{add_database}"
40
+
41
+ if add_database["id"]
42
+ ui.success "Database '#{database}' has been successfully created."
43
+ else
44
+ ui.fail AcquiaToolbelt::CLI::API.display_error(add_database)
45
+ end
46
+ end
47
+
48
+ # Public: Copy a database from one environment to another.
49
+ #
50
+ # Returns a status message.
51
+ desc "copy", "Copy a database from one environment to another."
52
+ method_option :database, :type => :string, :aliases => %w(-d), :required => true,
53
+ :desc => "Name of the database to copy."
54
+ method_option :origin, :type => :string, :aliases => %w(-o), :required => true,
55
+ :desc => "Origin of the database to copy."
56
+ method_option :target, :type => :string, :aliases => %w(-t), :required => true,
57
+ :desc => "Target of where to copy the database."
58
+ def copy
59
+ if options[:subscription]
60
+ subscription = options[:subscription]
61
+ else
62
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
63
+ end
64
+
65
+ database = options[:database]
66
+ origin = options[:origin]
67
+ target = options[:target]
68
+ copy_database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs/#{database}/db-copy/#{origin}/#{target}", "POST"
69
+
70
+ if copy_database["id"]
71
+ ui.success "Database '#{database}' has been copied from #{origin} to #{target}."
72
+ else
73
+ ui.fail AcquiaToolbelt::CLI::API.display_error(copy_database)
74
+ end
75
+ end
76
+
77
+ # Public: Delete a database from a subscription.
78
+ #
79
+ # NB: This will delete all instances of the database across all
80
+ # environments.
81
+ #
82
+ # Returns a status message.
83
+ desc "delete", "Delete a database."
84
+ method_option :database, :type => :string, :aliases => %w(-d), :required => true,
85
+ :desc => "Name of the database to delete."
86
+ def delete
87
+ if options[:subscription]
88
+ subscription = options[:subscription]
89
+ else
90
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
91
+ end
92
+
93
+ database = options[:database]
94
+ delete_db = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs/#{database}", "DELETE"
95
+
96
+ if delete_db["id"]
97
+ ui.success "Database '#{database}' has been successfully deleted."
98
+ else
99
+ ui.fail AcquiaToolbelt::CLI::API.display_error(delete_database)
100
+ end
101
+ end
102
+
103
+ # Public: List all databases available within a subscription.
104
+ #
105
+ # Returns a database listing.
106
+ desc "list", "List all databases."
107
+ method_option :database, :type => :string, :aliases => %w(-d),
108
+ :desc => "Name of the database to view."
109
+ def list
110
+ if options[:subscription]
111
+ subscription = options[:subscription]
112
+ else
113
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
114
+ end
115
+
116
+ database = options[:database]
117
+ environment = options[:environment]
118
+
119
+ # Output a single database where the name and environment are specified.
120
+ if database && environment
121
+ database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}"
122
+ ui.say
123
+ output_database_instance(database)
124
+
125
+ # Only an environment was set so get all expanded data for the requested
126
+ # environment.
127
+ elsif environment
128
+ databases = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs"
129
+ databases.each do |db|
130
+ ui.say
131
+ ui.say "#{db["name"]}"
132
+ output_database_instance(db)
133
+ end
134
+
135
+ # Just a general listing of the databases, no in depth details.
136
+ else
137
+ databases = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs"
138
+ ui.say
139
+ databases.each do |db|
140
+ say "> #{db["name"]}"
141
+ end
142
+ end
143
+ end
144
+
145
+ # Public: Create a database instance backup.
146
+ #
147
+ # Returns a status message.
148
+ desc "backup", "Create a new backup for a database."
149
+ method_option :database, :type => :string, :aliases => %w(-d), :required => true,
150
+ :desc => "Name of the database to backup."
151
+ def backup
152
+ if options[:subscription]
153
+ subscription = options[:subscription]
154
+ else
155
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
156
+ end
157
+
158
+ database = options[:database]
159
+ environment = options[:environment]
160
+ create_backup = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups", "POST"
161
+ if create_backup["id"]
162
+ ui.success "The backup for '#{database}' in #{environment} has been started."
163
+ else
164
+ ui.fail AcquiaToolbelt::CLI::API.display_error(create_backup)
165
+ end
166
+ end
167
+
168
+ # Public: List available database backups.
169
+ #
170
+ # Returns all database backups.
171
+ desc "list-backups", "List all database backups."
172
+ method_option :database, :type => :string, :aliases => %w(-d), :required => true,
173
+ :desc => "Name of the database to get the backup for."
174
+ def list_backups
175
+ # Ensure we have an environment defined.
176
+ if options[:environment].nil?
177
+ ui.say "No value provided for required options '--environment'"
178
+ return
179
+ end
180
+
181
+ if options[:subscription]
182
+ subscription = options[:subscription]
183
+ else
184
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
185
+ end
186
+
187
+ database = options[:database]
188
+ environment = options[:environment]
189
+ backups = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups"
190
+ backups.each do |backup|
191
+ ui.say
192
+ ui.say "> ID: #{backup["id"]}"
193
+ ui.say "> MD5: #{backup["checksum"]}"
194
+ ui.say "> Type: #{backup["type"]}"
195
+ ui.say "> Path: #{backup["path"]}"
196
+ ui.say "> Link: #{backup["link"]}"
197
+ ui.say "> Started: #{Time.at(backup["started"].to_i)}"
198
+ ui.say "> Completed: #{Time.at(backup["completed"].to_i)}"
199
+ end
200
+ end
201
+
202
+ # Public: Restore a database backup.
203
+ #
204
+ # Returns a status message.
205
+ desc "restore", "Restore a database from a backup."
206
+ method_option :id, :type => :string, :aliases => %w(-i),
207
+ :desc => "Backup ID to restore."
208
+ method_option :database, :type => :string, :aliases => %w(-d),
209
+ :desc => "Name of the database to restore."
210
+ def restore
211
+ # Ensure we have an environment defined.
212
+ if options[:environment].nil?
213
+ ui.say "No value provided for required options '--environment'"
214
+ return
215
+ end
216
+
217
+ if options[:subscription]
218
+ subscription = options[:subscription]
219
+ else
220
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
221
+ end
222
+
223
+ database = options[:database]
224
+ environment = options[:environment]
225
+ database = options[:database]
226
+ backup_id = options[:id]
227
+ restore_db = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups/#{backup_id}/restore", "POST"
228
+
229
+ if restore_db["id"]
230
+ ui.success "Database backup #{backup_id} has been restored to '#{database}' in #{environment}."
231
+ else
232
+ ui.fail AcquiaToolbelt::CLI::API.display_error(restore_db)
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,36 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Deploy < AcquiaToolbelt::Thor
4
+ # Public: Deploy a VCS branch or tag.
5
+ #
6
+ # Returns a status message.
7
+ desc "code", "Deploy a VCS branch or tag to an environment."
8
+ method_option :release, :type => :string, :aliases => %w(-r), :required => true,
9
+ :desc => "Name of the release to deploy to the environment."
10
+ def code
11
+ if options[:environment].nil?
12
+ ui.say "No value provided for required options '--environment'"
13
+ return
14
+ end
15
+
16
+ if options[:subscription]
17
+ subscription = options[:subscription]
18
+ else
19
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
20
+ end
21
+
22
+ environment = options[:environment]
23
+ release = options[:release]
24
+ data = { :key => "path", :value => "#{release}" }
25
+
26
+ deploy_code = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/code-deploy", "QUERY-STRING-POST", data
27
+
28
+ if deploy_code["id"]
29
+ ui.success "#{release} has been deployed to #{environment}."
30
+ else
31
+ ui.fail AcquiaToolbelt::CLI::API.display_error(deploy_code)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,177 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Domains < AcquiaToolbelt::Thor
4
+ no_tasks do
5
+ # Internal: Purge a web cache for a domain.
6
+ #
7
+ # Returns a status message.
8
+ def purge_domain(subscription, environment, domain)
9
+ # Ensure all the required fields are available.
10
+ if subscription.nil? || environment.nil? || domain.nil?
11
+ ui.fail "Purge request is missing a required parameter."
12
+ return
13
+ end
14
+
15
+ purge_request = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/domains/#{domain}/cache", "DELETE"
16
+
17
+ if purge_request["id"]
18
+ ui.success "#{domain} has been successfully purged."
19
+ else
20
+ ui.fail AcquiaToolbelt::CLI::API.display_error(purge_request)
21
+ end
22
+ end
23
+ end
24
+
25
+ # Public: List all domains on a subscription.
26
+ #
27
+ # Returns all domains.
28
+ desc "list", "List all domains."
29
+ def list
30
+ # Set the subscription if it has been passed through, otherwise use the
31
+ # default.
32
+ if options[:subscription]
33
+ subscription = options[:subscription]
34
+ else
35
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
36
+ end
37
+
38
+ # Get all the environments to loop over unless the environment is set.
39
+ if options[:environment]
40
+ environments = []
41
+ environments << options[:environment]
42
+ else
43
+ environments = AcquiaToolbelt::CLI::API.get_environments
44
+ end
45
+
46
+ environments.each do |environment|
47
+ domains = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/domains"
48
+ ui.say
49
+ ui.say "Environment: #{environment}" unless options[:environment]
50
+
51
+ domains.each do |domain|
52
+ ui.say "> #{domain["name"]}"
53
+ end
54
+ end
55
+ end
56
+
57
+ # Public: Add a domain to the subscription.
58
+ #
59
+ # Returns a status message.
60
+ desc "add", "Add a domain."
61
+ method_option :domain, :type => :string, :aliases => %w(-d), :required => true,
62
+ :desc => "Full URL of the domain to add - No slashes or protocols required."
63
+ def add
64
+ if options[:environment].nil?
65
+ ui.say "No value provided for required options '--environment'"
66
+ return
67
+ end
68
+
69
+ if options[:subscription]
70
+ subscription = options[:subscription]
71
+ else
72
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
73
+ end
74
+
75
+ environment = options[:environment]
76
+ domain = options[:domain]
77
+ add_domain = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/domains/#{domain}", "POST"
78
+
79
+ if add_domain["id"]
80
+ ui.success "Domain #{domain} has been successfully added to #{environment}."
81
+ else
82
+ ui.fail AcquiaToolbelt::CLI::API.display_error(add_domain)
83
+ end
84
+ end
85
+
86
+ # Public: Delete a domain from an environment.
87
+ #
88
+ # Returns a status message.
89
+ desc "delete", "Delete a domain."
90
+ method_option :domain, :type => :string, :aliases => %w(-d), :required => true,
91
+ :desc => "Full URL of the domain to delete - No slashes or protocols required."
92
+ def delete
93
+ if options[:subscription]
94
+ subscription = options[:subscription]
95
+ else
96
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
97
+ end
98
+
99
+ environment = options[:environment]
100
+ domain = options[:domain]
101
+ delete_domain = AcquiaToolbelt::CLI::API.request "/sites/#{subscription}/envs/#{environment}/domains/#{domain}", "DELETE"
102
+
103
+ if delete_domain["id"]
104
+ ui.success "Domain #{domain} has been successfully deleted from #{environment}."
105
+ else
106
+ ui.fail AcquiaToolbelt::CLI::API.display_error(delete_domain)
107
+ end
108
+ end
109
+
110
+ # Public: Purge a domains web cache.
111
+ #
112
+ # Returns a status message.
113
+ desc "purge", "Purge a domain's web cache."
114
+ method_option :domain, :type => :string, :aliases => %w(-d),
115
+ :desc => "URL of the domain to purge."
116
+ def purge
117
+ if options[:subscription]
118
+ subscription = options[:subscription]
119
+ else
120
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
121
+ end
122
+
123
+ domain = options[:domain]
124
+ environment = options[:environment]
125
+
126
+ # If the domain is not defined, we are going to clear a whole
127
+ # environment. This can have severe performance impacts on your
128
+ # environments. We need to be sure this is definitely what you want to
129
+ # do.
130
+ if domain
131
+ purge_domain(subscription, environment, domain)
132
+ else
133
+ all_env_clear = ui.ask "You are about to clear all domains in the #{environment} environment. Are you sure? (y/n)"
134
+ # Last chance to bail out.
135
+ if all_env_clear == "y"
136
+ domains = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/domains"
137
+ domains.each do |domain|
138
+ purge_domain("#{subscription}", "#{environment}", "#{domain["name"]}")
139
+ end
140
+ else
141
+ ui.info "Ok, no action has been taken."
142
+ end
143
+ end
144
+ end
145
+
146
+ # Public: Move domains from one environment to another.
147
+ #
148
+ # Returns a status message.
149
+ desc "move", "Move a domain to another environment."
150
+ method_option :domains, :type => :string, :aliases => %w(-d),
151
+ :desc => "List of comma separated domains to move."
152
+ method_option :origin, :type => :string, :aliases => %w(-o),
153
+ :desc => "Origin environment to move the domains from."
154
+ method_option :target, :type => :string, :aliases => %w(-t),
155
+ :desc => "Target environment to move the domains to."
156
+ def move
157
+ if options[:subscription]
158
+ subscription = options[:subscription]
159
+ else
160
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
161
+ end
162
+
163
+ domains = options[:domains].split(",")
164
+ origin = options[:origin]
165
+ target = options[:target]
166
+ data = { :domains => domains }
167
+
168
+ move_domain = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/domain-move/#{origin}/#{target}", "POST", data
169
+ if move_domain["id"]
170
+ ui.success "Domain move from #{origin} to #{target} has been successfully completed."
171
+ else
172
+ ui.fail AcquiaToolbelt::CLI::API.display_error(move_domain)
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,71 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Environments < AcquiaToolbelt::Thor
4
+ # Public: List environments on a subscription.
5
+ #
6
+ # Output environment information.
7
+ #
8
+ # Returns enviroment data.
9
+ desc "list", "List all environment data."
10
+ def list
11
+ if options[:subscription]
12
+ subscription = options[:subscription]
13
+ else
14
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
15
+ end
16
+
17
+ environment = options[:environment]
18
+
19
+ # If the environment option is set, just fetch a single environment.
20
+ if environment
21
+ environments = [environment]
22
+ else
23
+ environments = AcquiaToolbelt::CLI::API.get_environments
24
+ end
25
+
26
+ environments.each do |environment|
27
+ env_info = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}"
28
+ ui.say
29
+ ui.say "> Host: #{env_info["ssh_host"]}"
30
+ ui.say "> Environment: #{env_info["name"]}"
31
+ ui.say "> Current release: #{env_info["vcs_path"]}"
32
+ ui.say "> DB clusters: #{env_info["db_clusters"].join(', ')}"
33
+ ui.say "> Default domain: #{env_info["default_domain"]}"
34
+ end
35
+ end
36
+
37
+ # Public: Toggle whether live development is enabled on an environment.
38
+ #
39
+ # Valid actions are enable or disable.
40
+ #
41
+ # Returns a status message.
42
+ desc "live-development", "Enable/disbale live development on an environment."
43
+ method_option :action, :type => :string, :aliases => %w(-a), :required => true,
44
+ :desc => "Status of live development (enable/disable).",
45
+ :enum => ["enable", "disable"]
46
+ def live_development
47
+ if options[:environment].nil?
48
+ ui.say "No value provided for required options '--environment'"
49
+ return
50
+ end
51
+
52
+ if options[:subscription]
53
+ subscription = options[:subscription]
54
+ else
55
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
56
+ end
57
+
58
+ action = options[:action]
59
+ environment = options[:environment]
60
+
61
+ live_development_set = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/livedev/#{action}", "POST"
62
+
63
+ if live_development_set["id"]
64
+ ui.success "Live development has been successfully #{action}d on #{environment}."
65
+ else
66
+ ui.fail AcquiaToolbelt::CLI::API.display_error(live_development_set)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,31 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Files < AcquiaToolbelt::Thor
4
+ # Public: Copy files from one environment to another.
5
+ #
6
+ # Returns a status message from the task.
7
+ desc "copy", "Copy files from one environment to another."
8
+ method_option :origin, :type => :string, :aliases => %w(-o), :required => true,
9
+ :desc => "Source environment for the file copy."
10
+ method_option :target, :type => :string, :aliases => %w(-t), :required => true,
11
+ :desc => "Target environment for the file copy."
12
+ def copy
13
+ if options[:subscription]
14
+ subscription = options[:subscription]
15
+ else
16
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
17
+ end
18
+
19
+ source = options[:origin]
20
+ target = options[:target]
21
+ file_copy = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/files-copy/#{source}/#{target}", "POST"
22
+
23
+ if file_copy["id"]
24
+ ui.success "File copy from #{source} to #{target} has started."
25
+ else
26
+ ui.fail AcquiaToolbelt::CLI::API.display_error(file_copy)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,67 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Servers < AcquiaToolbelt::Thor
4
+ desc "list", "List all servers."
5
+ def list
6
+ if options[:subscription]
7
+ subscription = options[:subscription]
8
+ else
9
+ subscription = AcquiaToolbelt::CLI::API.default_subscription
10
+ end
11
+
12
+ environment = options[:environment]
13
+ # Determine if we want just a single environment, or all of them at once.
14
+ if environment
15
+ environments = [environment]
16
+ else
17
+ environments = AcquiaToolbelt::CLI::API.get_environments
18
+ end
19
+
20
+ # Loop over each environment and get all the associated server data.
21
+ environments.each do |environment|
22
+ ui.say
23
+ ui.say "Environment: #{environment}"
24
+
25
+ server_env = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/servers"
26
+ server_env.each do |server|
27
+ ui.say
28
+ ui.say "> Host: #{server["fqdn"]}"
29
+ ui.say "> Region: #{server["ec2_region"]}"
30
+ ui.say "> Instance type: #{server["ami_type"]}"
31
+ ui.say "> Availability zone: #{server["ec2_availability_zone"]}"
32
+
33
+ # Show how many PHP processes this node can have. Note, this is only
34
+ # available on the web servers.
35
+ if server["services"] && server["services"]["php_max_procs"]
36
+ ui.say "> PHP max processes: #{server["services"]["php_max_procs"]}"
37
+ end
38
+
39
+ if server["services"] && server["services"]["status"]
40
+ ui.say "> Status: #{server["services"]["status"]}"
41
+ end
42
+
43
+ if server["services"] && server["services"]["web"]
44
+ ui.say "> Web status: #{server["services"]["web"]["status"]}"
45
+ end
46
+
47
+ # The state of varnish.
48
+ if server["services"] && server["services"]["varnish"]
49
+ ui.say "> Varnish status: #{server["services"]["varnish"]["status"]}"
50
+ end
51
+
52
+ # Only load balancers will have the "external IP" property.
53
+ if server["services"] && server["services"]["external_ip"]
54
+ ui.say "> External IP: #{server["services"]["external_ip"]}"
55
+ end
56
+
57
+ # If running a dedicated load balancer, there will be a ELB domain
58
+ # associated with the load balancing tier.
59
+ if server["services"] && server["services"]["elb_domain_name"]
60
+ ui.say "> ELB hostname: #{server["services"]["elb_domain_name"]}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ module AcquiaToolbelt
2
+ class CLI
3
+ class Sites < AcquiaToolbelt::Thor
4
+ # Public: List all subscriptions the user has access to.
5
+ #
6
+ # Returns a list of subscriptions.
7
+ desc "list", "List all subscriptions you have access to."
8
+ def list
9
+ sites = AcquiaToolbelt::CLI::API.request "sites"
10
+
11
+ sites.each do |site|
12
+ ui.say
13
+ # Get the individual subscription information.
14
+ site_data = AcquiaToolbelt::CLI::API.request "sites/#{site}"
15
+
16
+ ui.say "#{site_data["title"]}"
17
+ ui.say "> Username: #{site_data["unix_username"]}"
18
+ ui.say "> Subscription: #{site_data["name"]}"
19
+
20
+ # If the VCS type is SVN, we want it in all uppercase, otherwise just
21
+ # capitilise it.
22
+ vcs_name = (site_data["vcs_type"] == "svn") ? site_data["vcs_type"].upcase : site_data["vcs_type"].capitalize
23
+ ui.say "> #{vcs_name} URL: #{site_data["vcs_url"]}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end