class Fog::Compute::Fogdocker::Real

Create attributes

'Hostname' => '', 'User' => '', 'Memory' => 0, 'MemorySwap' => 0, 'AttachStdin' => false, 'AttachStdout' => true, 'AttachStderr' => true, 'PortSpecs' => nil, 'Tty' => false, 'OpenStdin' => false, 'StdinOnce' => false, 'Env' => nil, 'Cmd' => ['date'], 'Dns' => nil, 'Image' => 'base', 'Volumes' => {

'/tmp' =>  {}

}, 'VolumesFrom' => '', 'WorkingDir' => '', 'ExposedPorts' => {

'22/tcp' => {}

}

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/fogdocker/compute.rb, line 36
def initialize(options={})
  require 'docker'
  username = options[:docker_username]
  password = options[:docker_password]
  email    = options[:docker_email]
  url      = options[:docker_url]

  connection_options = {:username => username, :password => password, :email => email}
  @connection = Docker::Connection.new(url, connection_options)
  Docker.authenticate!(connection_options, @connection) if username || email || password
rescue Docker::Error::AuthenticationError => e
  raise Fog::Errors::Fogdocker::AuthenticationError.new(e.message)
end

Public Instance Methods

api_version() click to toggle source
# File lib/fog/fogdocker/requests/compute/api_version.rb, line 5
def api_version
  Docker.version(@connection)
end
camelize_hash_keys(hash) click to toggle source
# File lib/fog/fogdocker/compute.rb, line 55
def camelize_hash_keys(hash)
  Hash[ hash.map {|k, v| [k.to_s.split('_').map {|w| w.capitalize}.join, v] }]
end
container_action(options = {}) click to toggle source
# File lib/fog/fogdocker/requests/compute/container_action.rb, line 5
def container_action(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  raise ArgumentError, "action is a required parameter" unless options.key? :action
  result = Docker::Container.get(options[:id], {}, @connection).send(options[:action], options[:options] || {})

  if result.is_a?(Hash)
    downcase_hash_keys(result)
  else
    result
  end
rescue Docker::Error::NotFoundError => e
  raise Fog::Errors::NotFound.new(e.message)
rescue Docker::Error::TimeoutError => e
  raise Fog::Errors::TimeoutError.new(e.message)
rescue Docker::Error::UnauthorizedError => e
  raise Fog::Errors::Fogdocker::AuthenticationError.new(e.message)
rescue Docker::Error::DockerError => e
  raise Fog::Errors::Fogdocker::ServiceError.new(e.message)
end
container_all(filters = {}) click to toggle source

filter options all – true or false, Show all containers. Only running containers are shown by default limit – Show limit last created containers, include non-running ones. since – Show only containers created since Id, include non-running ones. before – Show only containers created before Id, include non-running ones. size – true or false, Show the containers sizes

# File lib/fog/fogdocker/requests/compute/container_all.rb, line 11
def container_all(filters = {})
  Docker::Container.all(filters.merge(:all => true), @connection).map do |container|
    downcase_hash_keys(container.json)
  end
end
container_commit(options) click to toggle source
# File lib/fog/fogdocker/requests/compute/container_commit.rb, line 5
def container_commit(options)
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  container = Docker::Container.get(options[:id], {}, @connection)
  downcase_hash_keys container.commit(camelize_hash_keys(options)).json
end
container_create(attrs) click to toggle source
# File lib/fog/fogdocker/requests/compute/container_create.rb, line 29
def container_create(attrs)
  downcase_hash_keys Docker::Container.create(camelize_hash_keys(attrs), @connection).json
end
container_delete(options = {}) click to toggle source
# File lib/fog/fogdocker/requests/compute/container_delete.rb, line 5
def container_delete(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  container = Docker::Container.get(options[:id], {}, @connection)
  container.delete()
  true
end
container_get(id) click to toggle source
# File lib/fog/fogdocker/requests/compute/container_get.rb, line 5
def container_get(id)
  raw_container = Docker::Container.get(id, {}, @connection).json
  processed_container = downcase_hash_keys(raw_container)
  processed_container['hostconfig_port_bindings'] = raw_container['HostConfig']['PortBindings']
  processed_container['hostconfig_links']         = raw_container['HostConfig']['Links']
  processed_container['config_exposed_ports']     = raw_container['Config']['ExposedPorts']
  processed_container
end
downcase_hash_keys(hash, k = []) click to toggle source
# File lib/fog/fogdocker/compute.rb, line 50
def downcase_hash_keys(hash, k = [])
  return {k.join('_').gsub(/([a-z])([A-Z])/,'\1_\2').downcase => hash} unless hash.is_a?(Hash)
  hash.reduce({}){ |h, v| h.merge! downcase_hash_keys(v[-1], k + [v[0]]) }
end
image_all(filters = {}) click to toggle source
# File lib/fog/fogdocker/requests/compute/image_all.rb, line 5
def image_all(filters = {})
  Docker::Image.all({}, @connection).map do |image|
    downcase_hash_keys(image.json)
  end
end
image_create(attrs) click to toggle source
# File lib/fog/fogdocker/requests/compute/image_create.rb, line 5
def image_create(attrs)
  downcase_hash_keys Docker::Image.create(attrs, nil, @connection).json
end
image_delete(options = {}) click to toggle source
# File lib/fog/fogdocker/requests/compute/image_delete.rb, line 5
def image_delete(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  image = Docker::Image.get(options[:id], {}, @connection)
  image.remove()
end
image_get(id) click to toggle source
# File lib/fog/fogdocker/requests/compute/image_get.rb, line 5
def image_get(id)
  downcase_hash_keys Docker::Image.get(id, {}, @connection).json
end