bbcloud 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/.gitignore +4 -0
  2. data/LICENSE +19 -0
  3. data/README +34 -0
  4. data/Rakefile +2 -0
  5. data/bbcloud.gemspec +29 -0
  6. data/bin/brightbox-accounts +9 -0
  7. data/bin/brightbox-cloudips +9 -0
  8. data/bin/brightbox-config +9 -0
  9. data/bin/brightbox-images +9 -0
  10. data/bin/brightbox-servers +9 -0
  11. data/bin/brightbox-types +9 -0
  12. data/bin/brightbox-users +9 -0
  13. data/bin/brightbox-zones +9 -0
  14. data/lib/bbcloud/accounts.rb +39 -0
  15. data/lib/bbcloud/api.rb +107 -0
  16. data/lib/bbcloud/cli.rb +127 -0
  17. data/lib/bbcloud/cloud_ips.rb +40 -0
  18. data/lib/bbcloud/commands/accounts-list.rb +9 -0
  19. data/lib/bbcloud/commands/accounts-reset-ftp-password.rb +27 -0
  20. data/lib/bbcloud/commands/accounts-show.rb +18 -0
  21. data/lib/bbcloud/commands/cloudips-create.rb +21 -0
  22. data/lib/bbcloud/commands/cloudips-destroy.rb +37 -0
  23. data/lib/bbcloud/commands/cloudips-list.rb +11 -0
  24. data/lib/bbcloud/commands/cloudips-map.rb +55 -0
  25. data/lib/bbcloud/commands/cloudips-show.rb +13 -0
  26. data/lib/bbcloud/commands/cloudips-unmap.rb +32 -0
  27. data/lib/bbcloud/commands/config-client-add.rb +45 -0
  28. data/lib/bbcloud/commands/config-client-default.rb +24 -0
  29. data/lib/bbcloud/commands/config-client-remove.rb +25 -0
  30. data/lib/bbcloud/commands/images-destroy.rb +18 -0
  31. data/lib/bbcloud/commands/images-list.rb +19 -0
  32. data/lib/bbcloud/commands/images-show.rb +17 -0
  33. data/lib/bbcloud/commands/servers-create.rb +65 -0
  34. data/lib/bbcloud/commands/servers-destroy.rb +25 -0
  35. data/lib/bbcloud/commands/servers-list.rb +13 -0
  36. data/lib/bbcloud/commands/servers-restart.rb +30 -0
  37. data/lib/bbcloud/commands/servers-show.rb +47 -0
  38. data/lib/bbcloud/commands/servers-shutdown.rb +17 -0
  39. data/lib/bbcloud/commands/servers-snapshot.rb +17 -0
  40. data/lib/bbcloud/commands/servers-start.rb +18 -0
  41. data/lib/bbcloud/commands/servers-stop.rb +18 -0
  42. data/lib/bbcloud/commands/types-list.rb +10 -0
  43. data/lib/bbcloud/commands/types-show.rb +22 -0
  44. data/lib/bbcloud/commands/users-list.rb +10 -0
  45. data/lib/bbcloud/commands/users-show.rb +27 -0
  46. data/lib/bbcloud/commands/users-update.rb +39 -0
  47. data/lib/bbcloud/commands/zones-list.rb +9 -0
  48. data/lib/bbcloud/config.rb +92 -0
  49. data/lib/bbcloud/images.rb +44 -0
  50. data/lib/bbcloud/servers.rb +66 -0
  51. data/lib/bbcloud/tables.rb +95 -0
  52. data/lib/bbcloud/types.rb +43 -0
  53. data/lib/bbcloud/users.rb +47 -0
  54. data/lib/bbcloud/vendor/hirb/.gemspec +22 -0
  55. data/lib/bbcloud/vendor/hirb/CHANGELOG.rdoc +106 -0
  56. data/lib/bbcloud/vendor/hirb/LICENSE.txt +22 -0
  57. data/lib/bbcloud/vendor/hirb/README.rdoc +182 -0
  58. data/lib/bbcloud/vendor/hirb/Rakefile +35 -0
  59. data/lib/bbcloud/vendor/hirb/lib/bond/completions/hirb.rb +15 -0
  60. data/lib/bbcloud/vendor/hirb/lib/hirb/console.rb +43 -0
  61. data/lib/bbcloud/vendor/hirb/lib/hirb/dynamic_view.rb +113 -0
  62. data/lib/bbcloud/vendor/hirb/lib/hirb/formatter.rb +116 -0
  63. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/auto_table.rb +24 -0
  64. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/object_table.rb +14 -0
  65. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/parent_child_tree.rb +24 -0
  66. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/filters.rb +10 -0
  67. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/resizer.rb +82 -0
  68. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table.rb +323 -0
  69. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/tree.rb +181 -0
  70. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/vertical_table.rb +37 -0
  71. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers.rb +17 -0
  72. data/lib/bbcloud/vendor/hirb/lib/hirb/import_object.rb +10 -0
  73. data/lib/bbcloud/vendor/hirb/lib/hirb/menu.rb +221 -0
  74. data/lib/bbcloud/vendor/hirb/lib/hirb/pager.rb +95 -0
  75. data/lib/bbcloud/vendor/hirb/lib/hirb/string.rb +44 -0
  76. data/lib/bbcloud/vendor/hirb/lib/hirb/util.rb +96 -0
  77. data/lib/bbcloud/vendor/hirb/lib/hirb/version.rb +3 -0
  78. data/lib/bbcloud/vendor/hirb/lib/hirb/view.rb +284 -0
  79. data/lib/bbcloud/vendor/hirb/lib/hirb/views/couch_db.rb +11 -0
  80. data/lib/bbcloud/vendor/hirb/lib/hirb/views/misc_db.rb +15 -0
  81. data/lib/bbcloud/vendor/hirb/lib/hirb/views/mongo_db.rb +14 -0
  82. data/lib/bbcloud/vendor/hirb/lib/hirb/views/orm.rb +11 -0
  83. data/lib/bbcloud/vendor/hirb/lib/hirb/views/rails.rb +19 -0
  84. data/lib/bbcloud/vendor/hirb/lib/hirb/views.rb +8 -0
  85. data/lib/bbcloud/vendor/hirb/lib/hirb.rb +81 -0
  86. data/lib/bbcloud/vendor/hirb/test/auto_table_test.rb +30 -0
  87. data/lib/bbcloud/vendor/hirb/test/console_test.rb +27 -0
  88. data/lib/bbcloud/vendor/hirb/test/deps.rip +4 -0
  89. data/lib/bbcloud/vendor/hirb/test/dynamic_view_test.rb +94 -0
  90. data/lib/bbcloud/vendor/hirb/test/formatter_test.rb +171 -0
  91. data/lib/bbcloud/vendor/hirb/test/hirb_test.rb +39 -0
  92. data/lib/bbcloud/vendor/hirb/test/import_test.rb +9 -0
  93. data/lib/bbcloud/vendor/hirb/test/menu_test.rb +239 -0
  94. data/lib/bbcloud/vendor/hirb/test/object_table_test.rb +79 -0
  95. data/lib/bbcloud/vendor/hirb/test/pager_test.rb +162 -0
  96. data/lib/bbcloud/vendor/hirb/test/resizer_test.rb +62 -0
  97. data/lib/bbcloud/vendor/hirb/test/table_test.rb +550 -0
  98. data/lib/bbcloud/vendor/hirb/test/test_helper.rb +61 -0
  99. data/lib/bbcloud/vendor/hirb/test/tree_test.rb +184 -0
  100. data/lib/bbcloud/vendor/hirb/test/util_test.rb +59 -0
  101. data/lib/bbcloud/vendor/hirb/test/view_test.rb +172 -0
  102. data/lib/bbcloud/vendor/hirb/test/views_test.rb +13 -0
  103. data/lib/bbcloud/version.rb +3 -0
  104. data/lib/bbcloud/zones.rb +27 -0
  105. metadata +241 -0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ lib/bbcloud/vendor/
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Brightbox Systems Ltd.
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.
data/README ADDED
@@ -0,0 +1,34 @@
1
+ = Brightbox Cloud Command Line Interface
2
+
3
+ bbcloud is a cli tool to interact with the (forthcoming) Brightbox
4
+ cloud API.
5
+
6
+ http://www.brightbox.co.uk
7
+
8
+ == Packaging
9
+
10
+ === Vendoring libraries
11
+
12
+ gems can be vendored into lib/bbcloud/vendor for packaging and will be
13
+ prioritized over any gems.
14
+
15
+ === GEM packaging
16
+
17
+ The gem currently has our branch of fog vendored, as the official fog
18
+ gem doesn't have our work merged in yet.
19
+
20
+ === Debian/Ubuntu packaging
21
+
22
+ Any gems that have equivalent packages available are set as
23
+ dependencies to the Debian package. Any other gems are vendored prior
24
+ to packaging. These are:
25
+
26
+ * formatador (required by hirb)
27
+ * excon (required by fog)
28
+ * gli
29
+ * fog
30
+ * hirb
31
+ * ini
32
+
33
+ Rubygems support can be disabled by defining the DISABLE_RUBYGEMS
34
+ constant in lib/bbcloud/os_config.rb
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bbcloud.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bbcloud/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bbcloud"
7
+ s.version = Brightbox::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["John Leach"]
10
+ s.email = ["john@brightbox.co.uk"]
11
+ s.homepage = "http://docs.brightbox.com/cli"
12
+ s.summary = %q{The Brightbox cloud management system}
13
+ s.description = %q{Scripts to interact with the Brightbox cloud API}
14
+
15
+ s.rubyforge_project = "bbcloud"
16
+
17
+ s.files = `git ls-files`.split("\n") + `find lib/bbcloud/vendor`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'gli', '1.1.2'
23
+ # unless File.exists?(File.dirname(__FILE__) + 'lib/bbcloud/vendor/hirb')
24
+ # s.add_dependency 'hirb', '0.3.4'
25
+ # end
26
+ s.add_dependency 'brightbox-fog', '0.3.16'
27
+ s.add_dependency 'excon', '>=0.2.4'
28
+ s.add_dependency 'ini', '0.1.1'
29
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bbcloud/cli"
5
+ rescue LoadError
6
+ bbcloud_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(bbcloud_path)
8
+ require "bbcloud/cli"
9
+ end
@@ -0,0 +1,39 @@
1
+ module Brightbox
2
+ class Account < Api
3
+
4
+ def ram_free
5
+ [ram_limit.to_i - ram_used.to_i, 0].max
6
+ end
7
+
8
+ def to_row
9
+ attributes.merge({ :ram_free => ram_free,
10
+ :cloud_ip_limit => limits_cloudips
11
+ })
12
+ end
13
+
14
+ def self.all
15
+ a = conn.account
16
+ a.connection = conn
17
+ [new(a)]
18
+ end
19
+
20
+ def self.get(id)
21
+ a = conn.account
22
+ a.connection = conn
23
+ if a.id == id
24
+ new(a)
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def self.default_field_order
31
+ [:id, :name, :cloud_ip_limit, :ram_limit, :ram_used, :ram_free]
32
+ end
33
+
34
+ def to_s
35
+ @id
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,107 @@
1
+ module Brightbox
2
+ class Api
3
+ attr_reader :id
4
+ class ApiError < StandardError ; end
5
+ class NotFound < ApiError ; end
6
+ class Conflict < ApiError ; end
7
+ class InvalidRecord < ApiError ; end
8
+ class Forbidden < ApiError ; end
9
+
10
+ @@api = nil
11
+
12
+ def self.conn
13
+ if @@api
14
+ @@api
15
+ else
16
+ @@api = Fog::Brightbox::Compute.new CONFIG.to_fog
17
+ end
18
+ end
19
+
20
+ def initialize(m = nil)
21
+ if m.is_a? String
22
+ @id = m
23
+ elsif !m.nil?
24
+ @fog_model = m
25
+ @id = m.id
26
+ end
27
+ end
28
+
29
+ def fog_model
30
+ @fog_model ||= self.class.find(@id)
31
+ end
32
+
33
+ def exists?
34
+ !fog_model.nil?
35
+ rescue NotFound
36
+ false
37
+ end
38
+
39
+ def to_s
40
+ @id
41
+ end
42
+
43
+ def self.find(args = :all, options = {})
44
+ return nil if args.nil?
45
+ options = {
46
+ :order => :created_at,
47
+ }.merge options
48
+ objects = []
49
+ # get the data from the Api
50
+ if args == :all or (args.respond_to?(:empty?) and args.empty?)
51
+ objects = all
52
+ elsif args.respond_to? :collect
53
+ objects = args.collect do |arg|
54
+ cached_get(arg)
55
+ end
56
+ end
57
+ # wrap in our objects
58
+ objects.collect! { |o| new(o) unless o.nil? }
59
+ # Sort
60
+ objects.sort! do |a,b|
61
+ sort_method = options[:order]
62
+ begin
63
+ a.send(sort_method) <=> b.send(sort_method)
64
+ rescue NoMethodError
65
+ 0
66
+ end
67
+ end
68
+ if objects.size <= 1 and args.is_a? String
69
+ # This was a single lookup
70
+ objects.first
71
+ else
72
+ objects
73
+ end
74
+ end
75
+
76
+ def method_missing(m, *args)
77
+ if fog_model
78
+ fog_model.send(m, *args)
79
+ else
80
+ raise NoMethodError
81
+ end
82
+ end
83
+
84
+ def self.cached_get(id)
85
+ @cache = {} if @cache.nil?
86
+ value = @cache[id]
87
+ if value
88
+ value
89
+ else
90
+ debug "writing cache entry #{id}"
91
+ @cache[id] = get(id)
92
+ end
93
+ end
94
+
95
+ def self.find_by_handle(h)
96
+ find(:all).find { |o| o.handle == h }
97
+ end
98
+
99
+ def self.cache_all!
100
+ @cache = {}
101
+ all.each do |f|
102
+ @cache[f.id] = f
103
+ end
104
+ end
105
+
106
+ end
107
+ end
@@ -0,0 +1,127 @@
1
+ os_config = File.join(File.dirname(__FILE__), 'os_config.rb')
2
+ require os_config if File.exist? os_config
3
+
4
+ require "rubygems" unless defined?(DISABLE_RUBYGEMS)
5
+
6
+ # Add any vendored libraries into search path
7
+ Dir.glob(File.join(File.dirname(__FILE__), 'vendor/*')).each do |f|
8
+ $:.unshift File.join(f, 'lib')
9
+ end
10
+
11
+ begin
12
+ require 'json/ext'
13
+ rescue LoadError
14
+ require 'json/pure'
15
+ end
16
+
17
+ require 'date'
18
+ require 'gli'
19
+ require 'bbcloud/tables'
20
+ require 'brightbox-fog'
21
+
22
+ %w{api servers images types zones cloud_ips users accounts config version}.each do |f|
23
+ require File.join(File.dirname(__FILE__), f)
24
+ end
25
+
26
+ CONFIG = BBConfig.new
27
+
28
+ include Brightbox
29
+ include GLI
30
+
31
+ class Time
32
+ def rfc8601
33
+ self.strftime("%Y-%m-%dT%H:%M")
34
+ end
35
+ def to_s
36
+ rfc8601
37
+ end
38
+ end
39
+
40
+ def error(s='')
41
+ STDERR.write s
42
+ STDERR.write "\n"
43
+ STDERR.flush
44
+ end
45
+
46
+ def info(s='')
47
+ STDERR.write s
48
+ STDERR.write "\n"
49
+ STDERR.flush
50
+ end
51
+
52
+ def warn(s='')
53
+ info "WARN: #{s}"
54
+ end
55
+
56
+ def data(s)
57
+ STDOUT.write s
58
+ STDOUT.write "\n"
59
+ end
60
+
61
+ def debug(s)
62
+ if ENV['DEBUG']
63
+ STDERR.write "DEBUG: "
64
+ STDERR.write s
65
+ STDERR.write "\n"
66
+ end
67
+ end
68
+
69
+ # Global options
70
+ desc "Simple output (tab separated, don't draw fancy tables)"
71
+ switch [:s, :simple]
72
+
73
+ desc "Set the api client to use (named in #{CONFIG.config_filename})"
74
+ flag [:c, :client]
75
+
76
+ # Load the command libraries for the current group
77
+ cmd_group_name = File.basename($0).gsub(/brightbox\-/,'')
78
+ cmd_group_files = File.join(File.dirname(__FILE__), "commands/#{cmd_group_name}*.rb")
79
+ Dir.glob(cmd_group_files).each do |f|
80
+ load f
81
+ end
82
+
83
+ pre do |global_options,command,options,args|
84
+ CONFIG.client_name = global_options[:c] if global_options[:c]
85
+ info "INFO: client_id: #{CONFIG.client_name}" if CONFIG.clients.size > 1
86
+ true
87
+ end
88
+
89
+ on_error do |e|
90
+ case e
91
+ when Excon::Errors::ServiceUnavailable
92
+ error "Api currently unavailable"
93
+ when Excon::Errors::Error
94
+ if e.respond_to?(:response) and e.response.respond_to?(:body)
95
+ r = JSON.parse(e.response.body) rescue {}
96
+ if r['error']
97
+ if r['error'].is_a? Hash
98
+ # Most API errors
99
+ r = r['error']
100
+ error "ERROR: #{e.class}: #{r['name']}: #{r['summary']}"
101
+ else
102
+ # Auth error
103
+ error "ERROR: #{e.class}: #{r['error']}: #{r['error_description']}"
104
+ end
105
+ else
106
+ error "ERROR: #{e}"
107
+ end
108
+ else
109
+ error "ERROR: #{e}"
110
+ end
111
+ else
112
+ error "ERROR: #{e}"
113
+ end
114
+ debug e
115
+ debug e.class.to_s
116
+ debug e.backtrace.join("\n")
117
+ exit 1
118
+ end
119
+
120
+ desc 'Display version information'
121
+ command [:version] do |c|
122
+ c.action do |global_options, options, args|
123
+ info "Brightbox CLI version: #{Brightbox::VERSION}"
124
+ end
125
+ end
126
+
127
+ run ARGV
@@ -0,0 +1,40 @@
1
+ module Brightbox
2
+ class CloudIP < Api
3
+ def self.get id
4
+ conn.cloud_ips.get id
5
+ end
6
+
7
+ def self.all
8
+ conn.cloud_ips
9
+ end
10
+
11
+ def self.create
12
+ r = conn.create_cloud_ip
13
+ new(JSON.parse(r.body)["id"])
14
+ rescue Excon::Errors::Forbidden => e
15
+ response = JSON.parse(e.response.body) rescue {}
16
+ response = response.fetch("error", {})
17
+ raise Forbidden, "#{response["details"]}: #{response["summary"]}"
18
+ end
19
+
20
+ def attributes
21
+ fog_model.attributes
22
+ end
23
+
24
+ def to_row
25
+ attributes
26
+ end
27
+
28
+ def mapped?
29
+ status == 'mapped'
30
+ end
31
+
32
+ def self.default_field_order
33
+ [:id, :status, :public_ip, :server_id, :interface_id, :reverse_dns]
34
+ end
35
+
36
+ def <=>(b)
37
+ self.status <=> b.status
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ desc 'List accounts'
2
+ arg_name '[account-id...]'
3
+ command [:list] do |c|
4
+ c.action do |global_options, options, args|
5
+
6
+ accounts = Account.find(args).compact
7
+ render_table(accounts, global_options)
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ desc 'Reset FTP Library password'
2
+ arg_name 'account-id...'
3
+ command [:reset_ftp_password] do |c|
4
+
5
+ c.action do |global_options,options,args|
6
+
7
+ accounts = Account.find(args)
8
+
9
+ rows = []
10
+
11
+ accounts.each do |s|
12
+ info "Resetting ftp password for #{s}"
13
+ new_password = s.reset_ftp_password
14
+ o = s.to_row
15
+ o[:library_ftp_password] = new_password
16
+ rows << o
17
+ end
18
+
19
+ table_opts = global_options.merge({
20
+ :vertical => true,
21
+ :fields => [:id, :name, :library_ftp_host, :library_ftp_user, :library_ftp_password ]
22
+ })
23
+
24
+ render_table(rows, table_opts)
25
+
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ desc 'Show detailed account info'
2
+ arg_name 'account-id...'
3
+ command [:show] do |c|
4
+
5
+ c.action do |global_options,options,args|
6
+
7
+ accounts = Account.find(args).compact
8
+
9
+ table_opts = global_options.merge({
10
+ :vertical => true,
11
+ :fields => [:id, :name, :cloud_ip_limit, :ram_limit, :ram_used,
12
+ :ram_free, :library_ftp_host, :library_ftp_user ]
13
+ })
14
+
15
+ render_table(accounts, table_opts)
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ desc 'Create a new cloud ip'
2
+ command [:create] do |c|
3
+ c.desc "Number of cloud ips to create"
4
+ c.default_value 1
5
+ c.flag [:i, "count"]
6
+
7
+ c.action do |global_options, options, args|
8
+
9
+ if options[:i].to_s !~ /^[0-9]+$/
10
+ raise "count must be a number"
11
+ end
12
+
13
+ options[:i] = options[:i].to_i
14
+
15
+ ips = []
16
+ options[:i].times do
17
+ ips << CloudIP.create
18
+ end
19
+ render_table(ips, global_options)
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ desc 'destroy Cloud IPs'
2
+ arg_name '[cloudip-id...]'
3
+ command [:destroy] do |c|
4
+ c.desc "Unmap mapped ips before destroying them"
5
+ c.switch [:u, "unmap"]
6
+
7
+ c.action do |global_options,options,args|
8
+
9
+ if args.size < 1
10
+ raise "You must specify the cloud ip id you want to destroy"
11
+ end
12
+
13
+ args.each do |ip_id|
14
+
15
+ ip = CloudIP.find ip_id
16
+
17
+ raise "Cannot find cloud ip #{ip_id}" if ip.nil?
18
+
19
+ if ip.mapped?
20
+ if options[:u]
21
+ info "Unmapping cloud ip #{ip}"
22
+ ip.unmap
23
+ 3.times do
24
+ break unless ip.mapped?
25
+ sleep 1
26
+ ip.reload
27
+ end
28
+ else
29
+ raise "Cannot destroy mapped cloud ip #{ip}"
30
+ end
31
+ end
32
+ info "Destroying cloud ip #{ip.public_ip} (#{ip})"
33
+ ip.destroy
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ desc 'List CloudIPs'
2
+ arg_name '[cloudip-id...]'
3
+ command [:list] do |c|
4
+
5
+ c.action do |global_options,options,args|
6
+
7
+ ips = CloudIP.find args
8
+
9
+ render_table(ips.compact.sort, global_options)
10
+ end
11
+ end
@@ -0,0 +1,55 @@
1
+ desc 'map Cloud IPs'
2
+ arg_name 'cloudip-id server-id'
3
+ command [:map] do |c|
4
+ c.desc "Unmap mapped ips before remapping them"
5
+ c.switch [:u, "unmap"]
6
+
7
+ c.action do |global_options,options,args|
8
+
9
+ if args.size > 2
10
+ raise "Too many arguments"
11
+ end
12
+
13
+ if args.size < 2
14
+ raise "You must specify the cloud ip id and the server id"
15
+ end
16
+
17
+ ip_id = args.first
18
+
19
+ ip = CloudIP.find ip_id
20
+
21
+ raise "Cannot find ip #{ip_id}" if ip.nil?
22
+
23
+ if ip.mapped?
24
+ if options[:u]
25
+ info "Unmapping ip #{ip}"
26
+ ip.unmap
27
+ 3.times do
28
+ break unless ip.mapped?
29
+ sleep 1
30
+ ip.reload
31
+ end
32
+ else
33
+ raise "Refusing to map already mapped ip #{ip}"
34
+ end
35
+ end
36
+
37
+ server_id = args.last
38
+ server = Server.find server_id
39
+ raise "Cannot find server #{server_id}" if server.nil?
40
+
41
+ interface_id = server.interfaces.first["id"]
42
+ info "Mapping #{ip} to interface #{interface_id} on #{server}"
43
+
44
+ ip.map interface_id
45
+
46
+ # Wait up to 3 seconds for mapping to complete
47
+ 3.times do
48
+ sleep 1
49
+ ip.reload
50
+ break if ip.mapped?
51
+ end
52
+
53
+ render_table([ip], global_options)
54
+ end
55
+ end