bbcloud 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/bbcloud.gemspec +2 -2
  2. data/lib/bbcloud/api.rb +1 -1
  3. data/lib/bbcloud/cli.rb +8 -2
  4. data/lib/bbcloud/commands/servers-activate-cloud.rb +23 -0
  5. data/lib/bbcloud/commands/types-list.rb +1 -1
  6. data/lib/bbcloud/config.rb +1 -0
  7. data/lib/bbcloud/servers.rb +4 -0
  8. data/lib/bbcloud/types.rb +8 -0
  9. data/lib/bbcloud/vendor/fog/lib/fog/compute/brightbox.rb +162 -0
  10. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/account.rb +51 -0
  11. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ip.rb +47 -0
  12. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ips.rb +34 -0
  13. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavor.rb +33 -0
  14. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavors.rb +28 -0
  15. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/image.rb +56 -0
  16. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/images.rb +28 -0
  17. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancer.rb +50 -0
  18. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancers.rb +28 -0
  19. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/server.rb +108 -0
  20. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/servers.rb +29 -0
  21. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/user.rb +39 -0
  22. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/users.rb +29 -0
  23. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zone.rb +21 -0
  24. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zones.rb +29 -0
  25. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/activate_console_server.rb +20 -0
  26. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +20 -0
  27. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb +20 -0
  28. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_api_client.rb +19 -0
  29. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_cloud_ip.rb +19 -0
  30. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_image.rb +19 -0
  31. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_load_balancer.rb +19 -0
  32. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_server.rb +19 -0
  33. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_api_client.rb +20 -0
  34. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb +20 -0
  35. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_image.rb +20 -0
  36. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb +20 -0
  37. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_server.rb +20 -0
  38. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_account.rb +19 -0
  39. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_api_client.rb +20 -0
  40. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_cloud_ip.rb +20 -0
  41. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_image.rb +20 -0
  42. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_interface.rb +20 -0
  43. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_load_balancer.rb +20 -0
  44. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server.rb +20 -0
  45. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server_type.rb +20 -0
  46. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_user.rb +20 -0
  47. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_zone.rb +20 -0
  48. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_api_clients.rb +19 -0
  49. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_cloud_ips.rb +19 -0
  50. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_images.rb +19 -0
  51. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_load_balancers.rb +19 -0
  52. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_server_types.rb +19 -0
  53. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_servers.rb +19 -0
  54. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_users.rb +19 -0
  55. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_zones.rb +19 -0
  56. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/map_cloud_ip.rb +20 -0
  57. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +20 -0
  58. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb +20 -0
  59. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb +19 -0
  60. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/resize_server.rb +19 -0
  61. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/shutdown_server.rb +20 -0
  62. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/snapshot_server.rb +20 -0
  63. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/start_server.rb +20 -0
  64. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/stop_server.rb +20 -0
  65. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb +20 -0
  66. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_account.rb +20 -0
  67. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_api_client.rb +21 -0
  68. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_image.rb +21 -0
  69. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_load_balancer.rb +21 -0
  70. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_server.rb +21 -0
  71. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_user.rb +21 -0
  72. data/lib/bbcloud/vendor/fog/lib/fog/compute.rb +43 -0
  73. data/lib/bbcloud/vendor/fog/lib/fog/core/attributes.rb +178 -0
  74. data/lib/bbcloud/vendor/fog/lib/fog/core/collection.rb +127 -0
  75. data/lib/bbcloud/vendor/fog/lib/fog/core/connection.rb +35 -0
  76. data/lib/bbcloud/vendor/fog/lib/fog/core/credentials.rb +92 -0
  77. data/lib/bbcloud/vendor/fog/lib/fog/core/deprecation.rb +23 -0
  78. data/lib/bbcloud/vendor/fog/lib/fog/core/errors.rb +20 -0
  79. data/lib/bbcloud/vendor/fog/lib/fog/core/hmac.rb +48 -0
  80. data/lib/bbcloud/vendor/fog/lib/fog/core/mock.rb +68 -0
  81. data/lib/bbcloud/vendor/fog/lib/fog/core/model.rb +57 -0
  82. data/lib/bbcloud/vendor/fog/lib/fog/core/parser.rb +99 -0
  83. data/lib/bbcloud/vendor/fog/lib/fog/core/provider.rb +18 -0
  84. data/lib/bbcloud/vendor/fog/lib/fog/core/scp.rb +67 -0
  85. data/lib/bbcloud/vendor/fog/lib/fog/core/service.rb +175 -0
  86. data/lib/bbcloud/vendor/fog/lib/fog/core/ssh.rb +120 -0
  87. data/lib/bbcloud/vendor/fog/lib/fog/core/time.rb +27 -0
  88. data/lib/bbcloud/vendor/fog/lib/fog/core/wait_for.rb +17 -0
  89. data/lib/bbcloud/vendor/fog/lib/fog/core.rb +32 -0
  90. data/lib/bbcloud/vendor/fog/lib/fog/providers/brightbox.rb +9 -0
  91. data/lib/bbcloud/vendor/fog/lib/fog/providers.rb +9 -0
  92. data/lib/bbcloud/vendor/fog/lib/fog.rb +14 -0
  93. data/lib/bbcloud/version.rb +1 -1
  94. metadata +105 -26
@@ -0,0 +1,178 @@
1
+ module Fog
2
+ module Attributes
3
+ module ClassMethods
4
+
5
+ def _load(marshalled)
6
+ new(Marshal.load(marshalled))
7
+ end
8
+
9
+ def aliases
10
+ @aliases ||= {}
11
+ end
12
+
13
+ def attributes
14
+ @attributes ||= []
15
+ end
16
+
17
+ def attribute(name, options = {})
18
+ class_eval <<-EOS, __FILE__, __LINE__
19
+ def #{name}
20
+ attributes[:#{name}]
21
+ end
22
+ EOS
23
+ case options[:type]
24
+ when :boolean
25
+ class_eval <<-EOS, __FILE__, __LINE__
26
+ def #{name}=(new_#{name})
27
+ attributes[:#{name}] = case new_#{name}
28
+ when 'true'
29
+ true
30
+ when 'false'
31
+ false
32
+ end
33
+ end
34
+ EOS
35
+ when :float
36
+ class_eval <<-EOS, __FILE__, __LINE__
37
+ def #{name}=(new_#{name})
38
+ attributes[:#{name}] = new_#{name}.to_f
39
+ end
40
+ EOS
41
+ when :integer
42
+ class_eval <<-EOS, __FILE__, __LINE__
43
+ def #{name}=(new_#{name})
44
+ attributes[:#{name}] = new_#{name}.to_i
45
+ end
46
+ EOS
47
+ when :string
48
+ class_eval <<-EOS, __FILE__, __LINE__
49
+ def #{name}=(new_#{name})
50
+ attributes[:#{name}] = new_#{name}.to_s
51
+ end
52
+ EOS
53
+ when :time
54
+ class_eval <<-EOS, __FILE__, __LINE__
55
+ def #{name}=(new_#{name})
56
+ attributes[:#{name}] = if new_#{name}.nil? || new_#{name} == "" || new_#{name}.is_a?(Time)
57
+ new_#{name}
58
+ else
59
+ Time.parse(new_#{name})
60
+ end
61
+ end
62
+ EOS
63
+ when :array
64
+ class_eval <<-EOS, __FILE__, __LINE__
65
+ def #{name}=(new_#{name})
66
+ attributes[:#{name}] = [*new_#{name}]
67
+ end
68
+ EOS
69
+ else
70
+ if squash = options[:squash]
71
+ class_eval <<-EOS, __FILE__, __LINE__
72
+ def #{name}=(new_data)
73
+ if new_data.is_a?(Hash)
74
+ if new_data[:#{squash}] || new_data["#{squash}"]
75
+ attributes[:#{name}] = new_data[:#{squash}] || new_data["#{squash}"]
76
+ else
77
+ attributes[:#{name}] = [ new_data ]
78
+ end
79
+ else
80
+ attributes[:#{name}] = new_data
81
+ end
82
+ end
83
+ EOS
84
+ else
85
+ class_eval <<-EOS, __FILE__, __LINE__
86
+ def #{name}=(new_#{name})
87
+ attributes[:#{name}] = new_#{name}
88
+ end
89
+ EOS
90
+ end
91
+ end
92
+ @attributes ||= []
93
+ @attributes |= [name]
94
+ for new_alias in [*options[:aliases]]
95
+ aliases[new_alias] = name
96
+ end
97
+ end
98
+
99
+ def identity(name, options = {})
100
+ @identity = name
101
+ self.attribute(name, options)
102
+ end
103
+
104
+ def ignore_attributes(*args)
105
+ @ignored_attributes = args
106
+ end
107
+
108
+ def ignored_attributes
109
+ @ignored_attributes ||= []
110
+ end
111
+
112
+ end
113
+
114
+ module InstanceMethods
115
+
116
+ def _dump(level)
117
+ Marshal.dump(attributes)
118
+ end
119
+
120
+ def attributes
121
+ @attributes ||= {}
122
+ end
123
+
124
+ def identity
125
+ send(self.class.instance_variable_get('@identity'))
126
+ end
127
+
128
+ def identity=(new_identity)
129
+ send("#{self.class.instance_variable_get('@identity')}=", new_identity)
130
+ end
131
+
132
+ def merge_attributes(new_attributes = {})
133
+ for key, value in new_attributes
134
+ unless self.class.ignored_attributes.include?(key)
135
+ if aliased_key = self.class.aliases[key]
136
+ send("#{aliased_key}=", value)
137
+ elsif (public_methods | private_methods).detect {|method| ["#{key}=", :"#{key}="].include?(method)}
138
+ send("#{key}=", value)
139
+ else
140
+ attributes[key] = value
141
+ end
142
+ end
143
+ end
144
+ self
145
+ end
146
+
147
+ def new_record?
148
+ !identity
149
+ end
150
+
151
+ # check that the attributes specified in args exist and is not nil
152
+ def requires(*args)
153
+ missing = []
154
+ for arg in [:connection] | args
155
+ missing << arg unless send("#{arg}")
156
+ end
157
+ unless missing.empty?
158
+ if missing.length == 1
159
+ raise(ArgumentError, "#{missing.first} is required for this operation")
160
+ else
161
+ raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation")
162
+ end
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ def remap_attributes(attributes, mapping)
169
+ for key, value in mapping
170
+ if attributes.key?(key)
171
+ attributes[value] = attributes.delete(key)
172
+ end
173
+ end
174
+ end
175
+
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,127 @@
1
+ module Fog
2
+ class Collection < Array
3
+
4
+ extend Fog::Attributes::ClassMethods
5
+ include Fog::Attributes::InstanceMethods
6
+
7
+ Array.public_instance_methods(false).each do |method|
8
+ unless [:reject, :select].include?(method.to_sym)
9
+ class_eval <<-RUBY
10
+ def #{method}(*args)
11
+ unless @loaded
12
+ lazy_load
13
+ end
14
+ super
15
+ end
16
+ RUBY
17
+ end
18
+ end
19
+
20
+ %w[reject select].each do |method|
21
+ class_eval <<-RUBY
22
+ def #{method}(*args)
23
+ unless @loaded
24
+ lazy_load
25
+ end
26
+ data = super
27
+ result = self.clone.clear.concat(data)
28
+ end
29
+ RUBY
30
+ end
31
+
32
+ def self.model(new_model=nil)
33
+ if new_model == nil
34
+ @model
35
+ else
36
+ @model = new_model
37
+ end
38
+ end
39
+
40
+ attr_accessor :connection
41
+
42
+ remove_method :clear
43
+ def clear
44
+ @loaded = true
45
+ super
46
+ end
47
+
48
+ def create(attributes = {})
49
+ object = new(attributes)
50
+ object.save
51
+ object
52
+ end
53
+
54
+ def initialize(attributes = {})
55
+ @loaded = false
56
+ merge_attributes(attributes)
57
+ end
58
+
59
+ remove_method :inspect
60
+ def inspect
61
+ Thread.current[:formatador] ||= Formatador.new
62
+ data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
63
+ Thread.current[:formatador].indent do
64
+ unless self.class.attributes.empty?
65
+ data << "#{Thread.current[:formatador].indentation}"
66
+ data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
67
+ data << "\n"
68
+ end
69
+ data << "#{Thread.current[:formatador].indentation}["
70
+ unless self.empty?
71
+ data << "\n"
72
+ Thread.current[:formatador].indent do
73
+ data << self.map {|member| member.inspect}.join(",\n")
74
+ data << "\n"
75
+ end
76
+ data << Thread.current[:formatador].indentation
77
+ end
78
+ data << "]\n"
79
+ end
80
+ data << "#{Thread.current[:formatador].indentation}>"
81
+ data
82
+ end
83
+
84
+ def load(objects)
85
+ clear
86
+ for object in objects
87
+ self << new(object)
88
+ end
89
+ self
90
+ end
91
+
92
+ def model
93
+ self.class.instance_variable_get('@model')
94
+ end
95
+
96
+ def new(attributes = {})
97
+ model.new(
98
+ attributes.merge(
99
+ :collection => self,
100
+ :connection => connection
101
+ )
102
+ )
103
+ end
104
+
105
+ def reload
106
+ clear
107
+ lazy_load
108
+ self
109
+ end
110
+
111
+ def table(attributes = nil)
112
+ Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
113
+ end
114
+
115
+ def to_json
116
+ require 'json'
117
+ self.map {|member| member.attributes}.to_json
118
+ end
119
+
120
+ private
121
+
122
+ def lazy_load
123
+ self.all
124
+ end
125
+
126
+ end
127
+ end
@@ -0,0 +1,35 @@
1
+ module Fog
2
+ class Connection
3
+
4
+ def initialize(url, persistent=false, params={})
5
+ @excon = Excon.new(url, params)
6
+ @persistent = persistent
7
+ end
8
+
9
+ def request(params, &block)
10
+ unless @persistent
11
+ reset
12
+ end
13
+ unless block_given?
14
+ if (parser = params.delete(:parser))
15
+ body = Nokogiri::XML::SAX::PushParser.new(parser)
16
+ block = lambda { |chunk| body << chunk }
17
+ end
18
+ end
19
+
20
+ response = @excon.request(params, &block)
21
+
22
+ if parser
23
+ body.finish
24
+ response.body = parser.response
25
+ end
26
+
27
+ response
28
+ end
29
+
30
+ def reset
31
+ @excon.reset
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,92 @@
1
+ require 'yaml'
2
+
3
+ module Fog
4
+ require 'fog/core/deprecation'
5
+
6
+ # Assign a new credential to use from configuration file
7
+ # @param [String, Symbol] new_credential name of new credential to use
8
+ # @ return [String, Symbol] name of the new credential
9
+ def self.credential=(new_credential)
10
+ @credentials = nil
11
+ @credential = new_credential
12
+ end
13
+
14
+ # @return [String, Symbol] The credential to use in Fog
15
+ def self.credential
16
+ @credential ||= :default
17
+ end
18
+
19
+ # @return [String] The path for configuration_file
20
+ def self.credentials_path
21
+ @credential_path ||= File.expand_path(ENV["FOG_RC"] || '~/.fog')
22
+ end
23
+
24
+ # @return [String] The new path for credentials file
25
+ def self.credentials_path=(new_credentials_path)
26
+ @credentials = nil
27
+ @credential_path = new_credentials_path
28
+ end
29
+
30
+ # @return [Hash] The credentials pulled from the configuration file
31
+ # @raise [LoadError] Configuration unavailable in configuration file
32
+ def self.credentials
33
+ @credentials ||= begin
34
+ if File.exists?(credentials_path)
35
+ credentials = YAML.load_file(credentials_path)
36
+ (credentials && credentials[credential]) or raise LoadError.new(missing_credentials)
37
+ else
38
+ {}
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ # @return [String] The error message that will be raised, if credentials cannot be found
46
+ def self.missing_credentials
47
+ <<-YML
48
+ Missing Credentials
49
+
50
+ To run as '#{credential}', add the following to your resource config file: #{credentials_path}
51
+ An alternate file may be used by placing its path in the FOG_RC environment variable
52
+
53
+ #######################################################
54
+ # Fog Credentials File
55
+ #
56
+ # Key-value pairs should look like:
57
+ # :aws_access_key_id: 022QF06E7MXBSAMPLE
58
+ :#{credential}:
59
+ :aws_access_key_id:
60
+ :aws_secret_access_key:
61
+ :bluebox_api_key:
62
+ :bluebox_customer_id:
63
+ :brightbox_client_id:
64
+ :brightbox_secret:
65
+ :go_grid_api_key:
66
+ :go_grid_shared_secret:
67
+ :google_storage_access_key_id:
68
+ :google_storage_secret_access_key:
69
+ :linode_api_key:
70
+ :local_root:
71
+ :new_servers_password:
72
+ :new_servers_username:
73
+ :public_key_path:
74
+ :private_key_path:
75
+ :rackspace_api_key:
76
+ :rackspace_username:
77
+ :slicehost_password:
78
+ :terremark_username:
79
+ :terremark_password:
80
+ :voxel_api_key:
81
+ :voxel_api_secret:
82
+ :zerigo_email:
83
+ :zerigo_token:
84
+ :dnsimple_email:
85
+ :dnsimple_password:
86
+ #
87
+ # End of Fog Credentials File
88
+ #######################################################
89
+
90
+ YML
91
+ end
92
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Deprecation
3
+
4
+ def deprecate(older, newer)
5
+ module_eval <<-EOS, __FILE__, __LINE__
6
+ def #{older}(*args)
7
+ Formatador.display_line("[yellow][WARN] #{self} => ##{older} is deprecated, use ##{newer} instead[/] [light_black](#{caller.first})[/]")
8
+ send(:#{newer}, *args)
9
+ end
10
+ EOS
11
+ end
12
+
13
+ def self_deprecate(older, newer)
14
+ module_eval <<-EOS, __FILE__, __LINE__
15
+ def self.#{older}(*args)
16
+ Formatador.display_line("[yellow][WARN] #{self} => ##{older} is deprecated, use ##{newer} instead[/] [light_black](#{caller.first})[/]")
17
+ send(:#{newer}, *args)
18
+ end
19
+ EOS
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Errors
3
+
4
+ class Error < StandardError
5
+ attr_accessor :verbose
6
+
7
+ def self.slurp(error, message = nil)
8
+ new_error = new(message)
9
+ new_error.set_backtrace(error.backtrace)
10
+ new_error.verbose = error.message
11
+ new_error
12
+ end
13
+ end
14
+
15
+ class MockNotImplemented < Fog::Errors::Error; end
16
+
17
+ class NotFound < Fog::Errors::Error; end
18
+
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ module Fog
2
+ class HMAC
3
+
4
+ def initialize(type, key)
5
+ @key = key
6
+ case type
7
+ when 'sha1'
8
+ setup_sha1
9
+ when 'sha256'
10
+ setup_sha256
11
+ end
12
+ end
13
+
14
+ def sign(data)
15
+ @signer.call(data)
16
+ end
17
+
18
+ private
19
+
20
+ def setup_sha1
21
+ @digest = OpenSSL::Digest::Digest.new('sha1')
22
+ @signer = lambda do |data|
23
+ OpenSSL::HMAC.digest(@digest, @key, data)
24
+ end
25
+ end
26
+
27
+ def setup_sha256
28
+ begin
29
+ @digest = OpenSSL::Digest::Digest.new('sha256')
30
+ @signer = lambda do |data|
31
+ OpenSSL::HMAC.digest(@digest, @key, data)
32
+ end
33
+ rescue RuntimeError => error
34
+ unless error.message == 'Unsupported digest algorithm (sha256).'
35
+ raise error
36
+ else
37
+ require 'hmac-sha2'
38
+ @hmac = ::HMAC::SHA256.new(@key)
39
+ @signer = lambda do |data|
40
+ @hmac.update(data)
41
+ @hmac.digest
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,68 @@
1
+ module Fog
2
+
3
+ @mocking = false
4
+
5
+ def self.mock!
6
+ @mocking = true
7
+ end
8
+
9
+ def self.mock?
10
+ @mocking
11
+ end
12
+
13
+ def self.mocking?
14
+ @mocking
15
+ end
16
+
17
+ module Mock
18
+
19
+ @delay = 1
20
+ def self.delay
21
+ @delay
22
+ end
23
+
24
+ def self.delay=(new_delay)
25
+ raise ArgumentError, "delay must be non-negative" unless new_delay >= 0
26
+ @delay = new_delay
27
+ end
28
+
29
+ def self.not_implemented
30
+ raise Fog::Errors::MockNotImplemented.new("Contributions welcome!")
31
+ end
32
+
33
+ def self.random_base64(length)
34
+ random_selection(
35
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
36
+ length
37
+ )
38
+ end
39
+
40
+ def self.random_hex(length)
41
+ max = ('f' * length).to_i(16)
42
+ rand(max).to_s(16).rjust(length, '0')
43
+ end
44
+
45
+ def self.random_letters(length)
46
+ random_selection(
47
+ 'abcdefghijklmnopqrstuvwxyz',
48
+ length
49
+ )
50
+ end
51
+
52
+ def self.random_numbers(length)
53
+ max = ('9' * length).to_i
54
+ rand(max).to_s
55
+ end
56
+
57
+ def self.random_selection(characters, length)
58
+ selection = ''
59
+ length.times do
60
+ position = rand(characters.length)
61
+ selection << characters[position..position]
62
+ end
63
+ selection
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,57 @@
1
+ module Fog
2
+ class Model
3
+
4
+ extend Fog::Attributes::ClassMethods
5
+ include Fog::Attributes::InstanceMethods
6
+
7
+ attr_accessor :collection, :connection
8
+
9
+ def initialize(new_attributes = {})
10
+ merge_attributes(new_attributes)
11
+ end
12
+
13
+ def inspect
14
+ Thread.current[:formatador] ||= Formatador.new
15
+ data = "#{Thread.current[:formatador].indentation}<#{self.class.name}"
16
+ Thread.current[:formatador].indent do
17
+ unless self.class.attributes.empty?
18
+ data << "\n#{Thread.current[:formatador].indentation}"
19
+ data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
20
+ end
21
+ end
22
+ data << "\n#{Thread.current[:formatador].indentation}>"
23
+ data
24
+ end
25
+
26
+ def reload
27
+ requires :identity
28
+ if data = collection.get(identity)
29
+ new_attributes = data.attributes
30
+ merge_attributes(new_attributes)
31
+ self
32
+ end
33
+ end
34
+
35
+ def to_json
36
+ require 'json'
37
+ attributes.to_json
38
+ end
39
+
40
+ def wait_for(timeout=600, interval=1, &block)
41
+ reload
42
+ Fog.wait_for(timeout, interval) do
43
+ retries = 3
44
+ if reload
45
+ retries = 3
46
+ elsif retries > 0
47
+ retries -= 1
48
+ sleep(1)
49
+ elsif retries == 0
50
+ raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.")
51
+ end
52
+ instance_eval(&block)
53
+ end
54
+ end
55
+
56
+ end
57
+ end