Class: Fog::Compute::Fogdocker::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Fogdocker::Real
- Defined in:
- lib/fog/fogdocker/requests/compute/container_create.rb,
lib/fog/fogdocker/compute.rb,
lib/fog/fogdocker/requests/compute/image_all.rb,
lib/fog/fogdocker/requests/compute/image_get.rb,
lib/fog/fogdocker/requests/compute/api_version.rb,
lib/fog/fogdocker/requests/compute/image_create.rb,
lib/fog/fogdocker/requests/compute/image_delete.rb,
lib/fog/fogdocker/requests/compute/image_search.rb,
lib/fog/fogdocker/requests/compute/container_all.rb,
lib/fog/fogdocker/requests/compute/container_get.rb,
lib/fog/fogdocker/requests/compute/container_action.rb,
lib/fog/fogdocker/requests/compute/container_commit.rb,
lib/fog/fogdocker/requests/compute/container_delete.rb
Overview
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' => {}
}
Instance Method Summary collapse
- #api_version ⇒ Object
- #camelize_hash_keys(hash) ⇒ Object
- #container_action(options = {}) ⇒ Object
-
#container_all(filters = {}) ⇒ Object
filter options all – true or false, Show all containers.
- #container_commit(options) ⇒ Object
- #container_create(attrs) ⇒ Object
- #container_delete(options = {}) ⇒ Object
- #container_get(id) ⇒ Object
- #downcase_hash_keys(hash, k = []) ⇒ Object
- #image_all(filters = {}) ⇒ Object
- #image_create(attrs) ⇒ Object
- #image_delete(options = {}) ⇒ Object
- #image_get(id) ⇒ Object
- #image_search(query = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/fogdocker/compute.rb', line 36 def initialize(={}) require 'docker' username = [:docker_username] password = [:docker_password] email = [:docker_email] url = [:docker_url] = {:username => username, :password => password, :email => email} @connection = Docker::Connection.new(url, ) Docker.authenticate!(, @connection) if username || email || password rescue Docker::Error::AuthenticationError => e raise Fog::Errors::Fogdocker::AuthenticationError.new(e.) end |
Instance Method Details
#api_version ⇒ Object
5 6 7 |
# File 'lib/fog/fogdocker/requests/compute/api_version.rb', line 5 def api_version Docker.version(@connection) end |
#camelize_hash_keys(hash) ⇒ Object
55 56 57 |
# 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 = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/fogdocker/requests/compute/container_action.rb', line 5 def container_action( = {}) raise ArgumentError, "instance id is a required parameter" unless .key? :id raise ArgumentError, "action is a required parameter" unless .key? :action result = Docker::Container.get([:id], {}, @connection).send([:action], [:options] || {}) if result.is_a?(Hash) downcase_hash_keys(result) else result end rescue Docker::Error::NotFoundError => e raise Fog::Errors::NotFound.new(e.) rescue Docker::Error::TimeoutError => e raise Fog::Errors::TimeoutError.new(e.) rescue Docker::Error::UnauthorizedError => e raise Fog::Errors::Fogdocker::AuthenticationError.new(e.) rescue Docker::Error::DockerError => e raise Fog::Errors::Fogdocker::ServiceError.new(e.) end |
#container_all(filters = {}) ⇒ Object
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
11 12 13 14 15 |
# 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) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/fogdocker/requests/compute/container_commit.rb', line 5 def container_commit() raise ArgumentError, "instance id is a required parameter" unless .key? :id container = Docker::Container.get([:id], {}, @connection) downcase_hash_keys container.commit(camelize_hash_keys()).json end |
#container_create(attrs) ⇒ Object
29 30 31 |
# 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 = {}) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/fog/fogdocker/requests/compute/container_delete.rb', line 5 def container_delete( = {}) raise ArgumentError, "instance id is a required parameter" unless .key? :id container = Docker::Container.get([:id], {}, @connection) container.delete() true end |
#container_get(id) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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 = []) ⇒ Object
50 51 52 53 |
# 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 = {}) ⇒ Object
5 6 7 8 9 |
# 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) ⇒ Object
5 6 7 |
# 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 = {}) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/fogdocker/requests/compute/image_delete.rb', line 5 def image_delete( = {}) raise ArgumentError, "instance id is a required parameter" unless .key? :id image = Docker::Image.get([:id], {}, @connection) image.remove() end |
#image_get(id) ⇒ Object
5 6 7 |
# 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 |
#image_search(query = {}) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/fogdocker/requests/compute/image_search.rb', line 5 def image_search(query = {}) Docker::Util.parse_json(@connection.get('/images/search', query)).map do |image| downcase_hash_keys(image) end end |