1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

extended the server (container) attributes

This commit is contained in:
Amos Benari 2014-02-18 15:06:54 +02:00
parent 48ea032fff
commit 92dfcd5f6a
7 changed files with 31 additions and 28 deletions

View file

@ -44,17 +44,9 @@ module Fog
Docker.authenticate!('username' => username, 'password' => password, 'email' => email) unless username. nil? || username.empty?
end
def downcase_hash_keys(h)
if h.is_a?(Hash)
h.keys.each do |key|
new_key = key.to_s.downcase
h[new_key] = h.delete(key)
downcase_hash_keys(h[new_key])
end
elsif h.respond_to?(:each)
h.each { |e| downcase_hash_keys(e) }
end
h
def downcase_hash_keys(hash, k = [])
return {k.join('_').gsub(/([a-z])([A-Z])/,'\1_\2').downcase => hash} unless hash.is_a?(Hash)
hash.inject({}){ |h, v| h.merge! downcase_hash_keys(v[-1], k + [v[0]]) }
end
end

View file

@ -12,13 +12,16 @@ module Fog
attribute :name
attribute :created
attribute :ip
attribute :state
attribute :cpu_shares, :aliases => 'cpus'
attribute :memory
attribute :network_settings_ipaddress, :aliases => 'ipaddress'
attribute :network_settings_bridge, :aliases => 'bridge'
attribute :state_running
attribute :state_pid
attribute :config_cpu_shares, :aliases => 'cpus'
attribute :config_memory, :aliases => 'memory'
attribute :config_hostname, :aliases => 'hostname'
attribute :host
attribute :image
attribute :exposed_ports
attribute :config_exposed_ports, :aliases => 'exposed_ports'
attribute :volumes
#raw = {"ID"=>"2ce79789656e4f7474624be6496dc6d988899af30d556574389a19aade2f9650",
@ -71,11 +74,11 @@ module Fog
# }
def ready?
state['running'] == true
state_running == true
end
def stopped?
state['running'] == false
state_running == false
end
def mac

View file

@ -9,7 +9,9 @@ module Fog
# before Show only containers created before Id, include non-running ones.
# size true or false, Show the containers sizes
def container_all(filters = {})
downcase_hash_keys Docker::Container.all(filters.merge(:all => true)).map(&:info)
Docker::Container.all(filters.merge(:all => true)).map do |container|
downcase_hash_keys(container.info)
end
end
end
@ -21,7 +23,7 @@ module Fog
'command' => '/bin/bash',
'created' => '1389876158',
'status' => 'Up 45 hours',
'state' => {'running' => 'true'},
'state_running' => true,
'ports' => nil,
'sizerw' => 0,
'sizerootfs' => 0,

View file

@ -14,7 +14,11 @@ module Fog
'command' => '/bin/bash',
'created' => '1389876158',
'status' => 'Up 45 hours',
'state' => {'running' => 'true'},
'state_running' => true,
'config_cpu_shares' => '1',
'network_settings_ipaddress' => '172.17.0.2',
'config_memory' => '1024',
'config_hostname' => '21341234',
'ports' => nil,
'sizerw' => 0,
'sizerootfs' => 0,

View file

@ -3,7 +3,9 @@ module Fog
class Fogdocker
class Real
def image_all(filters = {})
downcase_hash_keys Docker::Image.all.map(&:info)
Docker::Image.all.map do |image|
downcase_hash_keys(image.info)
end
end
end
class Mock

View file

@ -20,7 +20,7 @@ Shindo.tests('Fog::Compute[:fogdocker] | image model', ['fogdocker']) do
end
end
tests("The attributes hash should have key") do
attributes.each do |attribute|
(attributes-[:repotags]).each do |attribute|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
end
end

View file

@ -20,11 +20,11 @@ Shindo.tests('Fog::Compute[:fogdocker] | server model', ['fogdocker']) do
attributes = [ :id,
:name,
:created,
#:ip,
:state,
#:config => cpu_shares,
#:config => memory,
#:config => hostname,
:network_settings_ipaddress,
:state_running,
:config_cpu_shares,
:config_memory,
:config_hostname,
:image,
#:config => exposed_ports,
#:config => volumes