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]

  Docker.url = url
  Docker.authenticate!('username' => username, 'password' => password, 'email' => email) unless username.nil? || username.empty?
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
end
camelize_hash_keys(hash) click to toggle source
# File lib/fog/fogdocker/compute.rb, line 52
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]).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::Error::NotFound.new(e.message)
rescue Docker::Error::TimeoutError => e
  raise Fog::Errors::Error::TimeoutError.new(e.message)
rescue Docker::Error::UnauthorizedError => e
  raise Fog::Errors::Fogdocker::ServiceError::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)).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])
  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)).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])
  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)
  downcase_hash_keys Docker::Container.get(id).json
end
downcase_hash_keys(hash, k = []) click to toggle source
# File lib/fog/fogdocker/compute.rb, line 47
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.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).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])
  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).json
end