Skip to content

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/brightbox-cli/vendor/fog/lib/fog/compute/models/brightbox/account.rb
  • Loading branch information
NeilW committed Oct 10, 2011
2 parents 93c382e + 7653e25 commit 0b1d94d
Show file tree
Hide file tree
Showing 1,222 changed files with 9,854 additions and 1,936 deletions.
3 changes: 0 additions & 3 deletions .bundle/config

This file was deleted.

1 change: 0 additions & 1 deletion brightbox-cli.gemspec
Expand Up @@ -24,7 +24,6 @@ Gem::Specification.new do |s|
s.add_dependency 'excon', '~> 0.6.1'
s.add_dependency 'builder'
s.add_dependency 'mime-types'
s.add_dependency 'multi_json', '~> 1.0.3'
s.add_dependency 'net-scp', '~> 1.0.4'
s.add_dependency 'net-ssh', '~> 2.2.1'
s.add_dependency 'nokogiri', '~> 1.5.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/brightbox-cli/api.rb
Expand Up @@ -71,7 +71,7 @@ def self.find(args = :all, options = {})
o
end
else
raise InvalidArguments, "Couldn't find '#{arg.class}'"
raise InvalidArguments, "Couldn't find '#{args.class}'"
end
if objects
# wrap in our objects
Expand Down
9 changes: 9 additions & 0 deletions lib/brightbox-cli/cloud_ips.rb
Expand Up @@ -42,5 +42,14 @@ def self.default_field_order
def <=>(b)
self.status <=> b.status
end

def update(options)
self.class.conn.update_cloud_ip(id, options)
self.reload
self
rescue Excon::Errors::BadRequest => e
raise Conflict, JSON.parse(e.response.body)['error']['details']
end

end
end
36 changes: 36 additions & 0 deletions lib/brightbox-cli/commands/cloudips-update.rb
@@ -0,0 +1,36 @@
module Brightbox
desc 'update Cloud IPs'
arg_name 'cloudip-id'
command [:update] do |c|
c.desc "Set reverse DNS for this cloud ip"
c.flag [:r, "reverse-dns"]

c.desc "Delete the reverse dns for this cloud ip"
c.switch ["delete-reverse-dns"]

c.action do |global_options,options,args|
cip_id = args.shift
raise "You must specify the cloud ip id as the first argument" unless cip_id =~ /^cip-/

if options[:r] && options[:r] != "" && options[:"delete-reverse-dns"]
raise "You must either specify a reverse dns record or --delete-reverse-dns"
end

cip = CloudIP.find cip_id

params = {}
if options[:r]
params[:reverse_dns] = options[:r]
end

if options[:"delete-reverse-dns"]
params[:reverse_dns] = ""
end

cip.update(params)
cip.reload

render_table([cip], global_options)
end
end
end
27 changes: 23 additions & 4 deletions lib/brightbox-cli/commands/images-register.rb
Expand Up @@ -11,8 +11,13 @@ module Brightbox
c.desc "Source filename of the image you uploaded to the image library"
c.flag [:s, "source"]

c.desc "This image does not support virtio so needs 'compatibility mode'"
c.switch [:c, "compatibility"]
c.desc "Set image mode to be either 'virtio' or 'compatibility'"
c.default_value "virtio"
c.flag [:m, "mode"]

c.desc "Set image to be publically visible (true or false)"
c.default_value "false"
c.flag [:p, "public"]

c.desc "Image description"
c.flag [:d, "description"]
Expand All @@ -21,10 +26,24 @@ module Brightbox

raise "You must specify the architecture" unless options[:a]
raise "You must specify the source filename" unless options[:s]
raise "Mode must be 'virtio' or 'compatibility'" unless options[:m] == "virtio" || options[:m] == "compatibility"
raise "Public must be true or false" unless options[:p] == "true" || options[:p] == "false"

if options[:m] == "compatibility"
compatibility_flag = true
else
compatibility_flag = false
end

if options[:p] == "true"
public_flag = true
else
public_flag = false
end

image = Image.register :name => options[:n], :arch => options[:a],
:source => options[:s], :compatibility_mode => options[:c],
:description => options[:d]
:source => options[:s], :compatibility_mode => compatibility_flag,
:description => options[:d], :public => public_flag

render_table([image])

Expand Down
2 changes: 1 addition & 1 deletion lib/brightbox-cli/commands/images-show.rb
Expand Up @@ -15,7 +15,7 @@ module Brightbox

table_opts = global_options.merge({
:vertical => true,
:fields => [:id, :type, :owner, :created_at, :status, :arch, :name, :description, :virtual_size, :disk_size, "compatibility_mode", :official, :ancestor_id ]
:fields => [:id, :type, :owner, :created_at, :status, :arch, :name, :description, :virtual_size, :disk_size, :public, :"compatibility_mode", :official, :ancestor_id ]
})

render_table(images, table_opts)
Expand Down
52 changes: 52 additions & 0 deletions lib/brightbox-cli/commands/images-update.rb
@@ -0,0 +1,52 @@
module Brightbox
desc 'Update an image'
arg_name 'img-id'
command [:update] do |c|

c.desc "Name to give the image"
c.flag [:n, "name"]

c.desc "Architecture of the image (i686 or x86_64)"
c.flag [:a, "arch"]

c.desc "Set image mode to be either 'virtio' or 'compatibility'"
c.flag [:m, "mode"]

c.desc "Set image to be publically visible (true or false)"
c.flag [:p, "public"]

c.desc "Image description"
c.flag [:d, "description"]

c.action do |global_options,options,args|
img_id = args.shift
raise "You must specify the image to update as the first argument" unless img_id =~ /^img-/
if options[:m]
raise "Mode must be 'virtio' or 'compatibility'" unless options[:m] == "virtio" || options[:m] == "compatibility"
end
if options[:p]
raise "Public must be true or false" unless options[:p] == "true" || options[:p] == "false"
end

params = {}
params[:name] = options[:n] if options[:n]
params[:arch] = options[:a] if options[:a]
params[:source] = options[:s] if options[:s]
params[:description] = options[:d] if options[:d]

params[:compatibility_mode] = true if options[:m] == "compatibility"
params[:compatibility_mode] = false if options[:m] == "virtio"

params[:public] = true if options[:p] == "true"
params[:public] = false if options[:p] == "false"

image = Image.find img_id

info "Updating image #{image}"
image.update params
image.reload
render_table([image], global_options)
end

end
end
2 changes: 1 addition & 1 deletion lib/brightbox-cli/commands/servers-show.rb
Expand Up @@ -39,7 +39,7 @@ module Brightbox

display_options = {
:vertical => true,
:fields => [:id, :status, :name, :description, :created_at, :deleted_at,
:fields => [:id, :status, :name, :created_at, :deleted_at,
:zone, :type, :type_name, :type_handle, :ram, :cores,
:disk, :image, :image_name, :private_ips, :cloud_ips, :ipv6_address,
:cloud_ip_ids, :hostname, :public_hostname, :snapshots
Expand Down
59 changes: 59 additions & 0 deletions lib/brightbox-cli/commands/servers-update.rb
@@ -0,0 +1,59 @@
module Brightbox
desc 'Update a server'
arg_name 'srv-id'
command [:update] do |c|
c.desc "Friendly name of server"
c.flag [:n, :name]

c.desc "Specify user data"
c.flag [:m, "user-data"]

c.desc "Specify the user data from a local file"
c.flag [:f, "user-data-file"]

c.desc "Don't base64 encode the user data"
c.switch [:e, :no_base64]

c.action do |global_options, options, args|
srv_id = args.shift
raise "You must specify a valid server id as the first argument" unless srv_id =~ /^srv-/

server = Server.find srv_id

user_data = options[:m]
user_data_file = options[:f]

if user_data_file
raise "Cannot specify user data on command line and in file at same time" if user_data
# Wot we use to read the data, be it from stdin or a file on disk
file_handler = lambda do |fh|
raise "User data file too big (>16k)" if fh.stat.size > 16 * 1024
user_data = fh.read
end
# Figure out how to invoke file_handler, and then invoke it
if user_data_file == "-"
file_handler[$stdin]
else
File.open user_data_file, "r", &file_handler
end
end

if user_data
unless options[:e]
require 'base64'
user_data = Base64.encode64(user_data)
end
raise "User data too big (>16k)" if user_data.size > 16 * 1024
end

params = {}
params[:name] = options[:n] if options[:n]
params[:user_data] = user_data if user_data

info "Updating server #{server}#{" with %.2fk of user data" % (user_data.size / 1024.0) if user_data}"
server.update params
server.reload
render_table([server], global_options)
end
end
end
3 changes: 2 additions & 1 deletion lib/brightbox-cli/config.rb
Expand Up @@ -117,7 +117,8 @@ def to_fog
:brightbox_api_url => c['api_url'],
:brightbox_auth_url => c['auth_url'] || c['api_url'],
:brightbox_client_id => c['client_id'],
:brightbox_secret => c['secret']
:brightbox_secret => c['secret'],
:persistent => (c["persistent"] != nil ? c["persistent"] : true)
}
end

Expand Down
10 changes: 0 additions & 10 deletions lib/brightbox-cli/fog_extensions.rb
@@ -1,13 +1,3 @@
# Hack to force persistent connections in fog
module Fog
class Connection
def initialize(url, persistent=false)
@excon = Excon.new(url)
@persistent = true
end
end
end

Fog::Compute::Brightbox::Real.class_eval do |klass|
klass.send(:attr_accessor, :oauth_token)
end
2 changes: 1 addition & 1 deletion lib/brightbox-cli/gli_global_hooks.rb
Expand Up @@ -50,7 +50,7 @@ def post_connection_check(hostname)
desc 'Display version information'
command [:version] do |c|
c.action do |global_options, options, args|
info "Brightbox CLI version: #{Brightbox::VERSION}, Fog version: #{Fog::VERSION}"
info "Brightbox CLI version: #{Brightbox::VERSION}"
end
end
end
41 changes: 25 additions & 16 deletions lib/brightbox-cli/images.rb
@@ -1,6 +1,31 @@
module Brightbox
class Image < Api

def self.all
conn.images
end

def self.get(id)
conn.images.get(id)
end

def self.register(options = {})
image = conn.create_image(options)
find image['id']
end

def self.default_field_order
[:id, :owner, :type, :created_on, :status, :size, :name]
end

def update options
self.class.conn.update_image(id, options)
self.reload
self
rescue Excon::Errors::BadRequest => e
raise Conflict, JSON.parse(e.response.body)['error']['details']
end

def to_row
o = fog_model.attributes
o[:id] = fog_model.id
Expand All @@ -25,25 +50,9 @@ def to_row
o
end

def self.register(options = {})
image = conn.create_image(options)
find image['id']
end

def public?
public
end

def self.all
conn.images
end

def self.get(id)
conn.images.get(id)
end

def self.default_field_order
[:id, :owner, :type, :created_on, :status, :size, :name]
end
end
end

0 comments on commit 0b1d94d

Please sign in to comment.