Class: Fog::Bluebox::Real

Inherits:
Object
  • Object
show all
Includes:
Collections
Defined in:
lib/fog/bluebox.rb,
lib/fog/bluebox/requests/get_block.rb,
lib/fog/bluebox/requests/get_blocks.rb,
lib/fog/bluebox/requests/get_product.rb,
lib/fog/bluebox/requests/create_block.rb,
lib/fog/bluebox/requests/get_products.rb,
lib/fog/bluebox/requests/get_template.rb,
lib/fog/bluebox/requests/reboot_block.rb,
lib/fog/bluebox/requests/destroy_block.rb,
lib/fog/bluebox/requests/get_templates.rb

Instance Method Summary collapse

Methods included from Collections

#flavors, #images, #servers

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



50
51
52
53
54
55
56
57
# File 'lib/fog/bluebox.rb', line 50

def initialize(options={})
  @bluebox_api_key      = options[:bluebox_api_key]
  @bluebox_customer_id  = options[:bluebox_customer_id]
  @host   = options[:bluebox_host]    || "boxpanel.blueboxgrp.com"
  @port   = options[:bluebox_port]    || 443
  @scheme = options[:bluebox_scheme]  || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

Instance Method Details

#create_block(product_id, template_id, options = {}) ⇒ Object

Create a new block

Parameters

  • product_id<~Integer> - Id of product to create block with

  • template_id<~Integer> - Id of template to create block with

  • options<~Hash>:

    * password<~String> - Password for block
    

    or

    * ssh_key<~String> - ssh public key
    
    • username<~String> - optional, defaults to deploy

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

TODO



20
21
22
23
24
25
26
27
# File 'lib/fog/bluebox/requests/create_block.rb', line 20

def create_block(product_id, template_id, options = {})
  request(
    :expects  => 200,
    :method   => 'POST',
    :path     => '/api/blocks.json',
    :query    => {'product' => product_id, 'template' => template_id}.merge!(options)
  )
end

#destroy_block(block_id) ⇒ Object

Destroy a block

Parameters

  • block_id<~Integer> - Id of block to destroy

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

TODO



14
15
16
17
18
19
20
# File 'lib/fog/bluebox/requests/destroy_block.rb', line 14

def destroy_block(block_id)
  request(
    :expects  => 200,
    :method   => 'DELETE',
    :path     => "api/blocks/#{block_id}.json"
  )
end

#get_block(block_id) ⇒ Object

Get details of a block.

Parameters

  • block_id<~Integer> - Id of block to lookup

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

TODO



14
15
16
17
18
19
20
# File 'lib/fog/bluebox/requests/get_block.rb', line 14

def get_block(block_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/blocks/#{block_id}.json"
  )
end

#get_blocksObject

Get list of blocks

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘ips’<~Array> - Ip addresses for the block

      • ‘id’<~String> - Id of the block

      • ‘storage’<~Integer> - Disk space quota for the block

      • ‘memory’<~Integer> - RAM quota for the block

      • ‘cpu’<~Float> - The fractional CPU quota for this block

      • ‘hostname’<~String> - The hostname for the block



16
17
18
19
20
21
22
# File 'lib/fog/bluebox/requests/get_blocks.rb', line 16

def get_blocks
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => 'api/blocks.json'
  )
end

#get_product(product_id) ⇒ Object

Get details of a product

Parameters

  • product_id<~Integer> - Id of flavor to lookup

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO



14
15
16
17
18
19
20
# File 'lib/fog/bluebox/requests/get_product.rb', line 14

def get_product(product_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/block_products/#{product_id}.json"
  )
end

#get_productsObject

Get list of products

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘id’<~String> - UUID of the product

      • ‘description’<~String> - Description of the product

      • ‘cost’<~Decimal> - Hourly cost of the product



13
14
15
16
17
18
19
# File 'lib/fog/bluebox/requests/get_products.rb', line 13

def get_products
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => 'api/block_products.json'
  )
end

#get_template(template_id) ⇒ Object

Get details of a template

Parameters

  • template_id<~Integer> - Id of template to lookup

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO



14
15
16
17
18
19
20
# File 'lib/fog/bluebox/requests/get_template.rb', line 14

def get_template(template_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/block_templates/#{template_id}.json"
  )
end

#get_templatesObject

Get list of OS templates

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘id’<~String> - UUID of the image

      • ‘description’<~String> - Description of the image

      • ‘public’<~Boolean> - Public / Private image

      • ‘created’<~Datetime> - Timestamp of when the image was created



14
15
16
17
18
19
20
# File 'lib/fog/bluebox/requests/get_templates.rb', line 14

def get_templates
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => 'api/block_templates.json'
  )
end

#reboot_block(block_id, type = 'SOFT') ⇒ Object

Reboot block

Parameters

  • block_id<~String> - Id of block to reboot

  • type<~String> - Type of reboot, must be in [‘HARD’, ‘SOFT’]

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

TODO



15
16
17
18
19
20
21
# File 'lib/fog/bluebox/requests/reboot_block.rb', line 15

def reboot_block(block_id, type = 'SOFT')
  request(
    :expects  => 200,
    :method   => 'PUT',
    :path     => "api/blocks/#{block_id}/#{'soft_' if type == 'SOFT'}reboot.json"
  )
end

#reloadObject



59
60
61
# File 'lib/fog/bluebox.rb', line 59

def reload
  @connection.reset
end

#request(params) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/bluebox.rb', line 63

def request(params)
  params[:headers] ||= {}
  params[:headers].merge!({
    'Authorization' => "Basic #{Base64.encode64([@bluebox_customer_id, @bluebox_api_key].join(':')).delete("\r\n")}"
  })

  begin
    response = @connection.request(params.merge!({:host => @host}))
  rescue Excon::Errors::Error => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Bluebox::NotFound.slurp(error)
    else
      error
    end
  end
  unless response.body.empty?
    response.body = JSON.parse(response.body)
  end
  response
end