openstack_activeresource 0.1.1

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 (47) hide show
  1. data/.document +5 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +49 -0
  4. data/LICENSE.txt +14 -0
  5. data/README.rdoc +427 -0
  6. data/Rakefile +44 -0
  7. data/VERSION +1 -0
  8. data/lib/hot_fixes.rb +55 -0
  9. data/lib/locales/en.yml +5 -0
  10. data/lib/open_stack/base.rb +88 -0
  11. data/lib/open_stack/common.rb +56 -0
  12. data/lib/open_stack/glance/base.rb +39 -0
  13. data/lib/open_stack/glance/image.rb +33 -0
  14. data/lib/open_stack/glance.rb +27 -0
  15. data/lib/open_stack/keystone/admin/base.rb +41 -0
  16. data/lib/open_stack/keystone/admin/role.rb +35 -0
  17. data/lib/open_stack/keystone/admin/tenant.rb +104 -0
  18. data/lib/open_stack/keystone/admin/user.rb +98 -0
  19. data/lib/open_stack/keystone/admin/user_role.rb +34 -0
  20. data/lib/open_stack/keystone/admin.rb +32 -0
  21. data/lib/open_stack/keystone/public/auth.rb +141 -0
  22. data/lib/open_stack/keystone/public/base.rb +41 -0
  23. data/lib/open_stack/keystone/public/tenant.rb +64 -0
  24. data/lib/open_stack/keystone/public.rb +31 -0
  25. data/lib/open_stack/keystone.rb +27 -0
  26. data/lib/open_stack/nova/compute/base.rb +41 -0
  27. data/lib/open_stack/nova/compute/base_detail.rb +59 -0
  28. data/lib/open_stack/nova/compute/flavor.rb +56 -0
  29. data/lib/open_stack/nova/compute/floating_ip.rb +61 -0
  30. data/lib/open_stack/nova/compute/floating_ip_pool.rb +36 -0
  31. data/lib/open_stack/nova/compute/image.rb +76 -0
  32. data/lib/open_stack/nova/compute/key_pair.rb +47 -0
  33. data/lib/open_stack/nova/compute/network.rb +45 -0
  34. data/lib/open_stack/nova/compute/security_group.rb +117 -0
  35. data/lib/open_stack/nova/compute/server.rb +313 -0
  36. data/lib/open_stack/nova/compute/simple_tenant_usage.rb +128 -0
  37. data/lib/open_stack/nova/compute/volume_attachment.rb +98 -0
  38. data/lib/open_stack/nova/compute.rb +39 -0
  39. data/lib/open_stack/nova/volume/base.rb +41 -0
  40. data/lib/open_stack/nova/volume/volume.rb +77 -0
  41. data/lib/open_stack/nova/volume.rb +29 -0
  42. data/lib/open_stack/nova.rb +27 -0
  43. data/lib/open_stack.rb +40 -0
  44. data/lib/openstack_activeresource.rb +1 -0
  45. data/test/helper.rb +18 -0
  46. data/test/test_openstack-activeresource.rb +7 -0
  47. metadata +190 -0
@@ -0,0 +1,141 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Keystone
20
+ module Public
21
+
22
+ class Auth < Base
23
+ self.element_name = "token"
24
+
25
+ schema do
26
+ attribute :username, :string
27
+ attribute :password, :string
28
+ attribute :tenant_id, :string
29
+ end
30
+
31
+ validates :username, :presence => true, :unless => Proc.new { token.present? }
32
+ validates :password, :presence => true, :unless => Proc.new { token.present? }
33
+
34
+ def initialize(attributes = {}, persisted = false)
35
+ attributes[:username] ||= ""
36
+ attributes[:password] ||= ""
37
+
38
+ if attributes[:tenant].present?
39
+ attributes[:tenant_id] = attributes[:tenant].id
40
+ elsif attributes[:tenant_id].present?
41
+ attributes[:tenant_id] = attributes[:tenant_id]
42
+ end
43
+
44
+ super(attributes, persisted)
45
+ end
46
+
47
+ # Overload ActiveRecord::encode method
48
+ # Custom encoding to deal with openstack API
49
+ def encode(options={})
50
+ to_encode = {}
51
+ if token.present?
52
+ to_encode[:auth] = {
53
+ :token => {
54
+ :id => token_id
55
+ }
56
+ }
57
+ else
58
+ to_encode[:auth] = {
59
+ :passwordCredentials => {
60
+ :username => username,
61
+ :password => password
62
+ }
63
+ }
64
+ end
65
+
66
+ to_encode[:auth][:tenantId] = tenant_id if @attributes[:tenant_id].present?
67
+
68
+ to_encode.send("to_#{self.class.format.extension}", options)
69
+ end
70
+
71
+ # Catch some exceptions to perform "remote validation" of this resource
72
+ def save
73
+ super
74
+ rescue ActiveResource::UnauthorizedAccess
75
+ errors.add :password, I18n.t(:is_invalid)
76
+ return false
77
+ end
78
+
79
+ def service_catalog
80
+ @attributes[:serviceCatalog].is_a?(Array) ? @attributes[:serviceCatalog] : []
81
+ end
82
+
83
+ def token
84
+ @attributes[:token]
85
+ end
86
+
87
+ def token_id
88
+ token.id if token.present?
89
+ end
90
+
91
+ def endpoints_for(endpoint_type, region=nil)
92
+ return [] unless service_catalog.present?
93
+
94
+ endpoints = []
95
+ service_catalog.each { |c|
96
+ next if c.attributes[:type] != endpoint_type
97
+
98
+ c.endpoints.each { |e|
99
+ if region.nil? or e.region == region
100
+ endpoints << e
101
+ end
102
+ }
103
+ }
104
+
105
+ endpoints
106
+ end
107
+
108
+ def endpoint_for(endpoint_type, region=nil)
109
+ endpoints_for(endpoint_type, region)[0]
110
+ end
111
+
112
+ end
113
+
114
+ class Auth::Token < Base
115
+ schema do
116
+ attribute :expires, :string
117
+ end
118
+
119
+ def initialize(attributes = {}, persisted = false)
120
+ attributes = attributes.with_indifferent_access
121
+ new_attributes = {
122
+ :id => attributes[:id],
123
+ :expires => attributes[:expires]
124
+ }
125
+
126
+ super(new_attributes, persisted)
127
+ end
128
+
129
+ def expires_at
130
+ DateTime.strptime(attributes[:expires], OpenStack::DATETIME_FORMAT)
131
+ end
132
+
133
+ def expired?
134
+ DateTime.strptime(attributes[:expires], OpenStack::DATETIME_FORMAT) < DateTime.now.utc
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,41 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Keystone
20
+ module Public
21
+
22
+ class Base < OpenStack::Common
23
+
24
+ def self.site
25
+ if self == OpenStack::Keystone::Public::Base
26
+ Thread.current[:open_stack_keystone_public_site]
27
+ else
28
+ super
29
+ end
30
+ end
31
+
32
+ def self.site=(site)
33
+ super(site)
34
+ Thread.current[:open_stack_keystone_public_site] = @site
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,64 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Keystone
20
+ module Public
21
+
22
+ class Tenant < Base
23
+
24
+ schema do
25
+ attribute :name, :string
26
+ attribute :description, :string
27
+ attribute :enabled, :boolean
28
+
29
+ end
30
+
31
+ def self.find_every(options)
32
+ class_name = self.name.split('::').last.downcase
33
+ begin
34
+ case from = options[:from]
35
+ when Symbol
36
+ instantiate_collection(get(from, options[:params]))
37
+ when String
38
+ path = "#{from}#{query_string(options[:params])}"
39
+ instantiate_collection(format.decode(connection.get(path, headers).body)[class_name.pluralize] || [])
40
+ else
41
+ prefix_options, query_options = split_options(options[:params])
42
+ path = collection_path(prefix_options, query_options)
43
+ instantiate_collection((format.decode(connection.get(path, headers).body)[class_name.pluralize] || []), prefix_options)
44
+ end
45
+ rescue ActiveResource::ResourceNotFound
46
+ # Swallowing ResourceNotFound exceptions and return nil - as per
47
+ # ActiveRecord.
48
+ nil
49
+ end
50
+ end
51
+
52
+ def self.find_by_name(name)
53
+ self.all.each { |tenant| return tenant if tenant.name == name }
54
+ end
55
+
56
+ def self.find_all_by_name(name)
57
+ self.all.reject! { |tenant| tenant.name != name }
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,31 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Keystone
20
+
21
+ module Public
22
+ extend ActiveSupport::Autoload
23
+
24
+ autoload :Base
25
+ autoload :Auth
26
+ autoload :Tenant
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+
20
+ module Keystone
21
+ extend ActiveSupport::Autoload
22
+
23
+ autoload :Admin
24
+ autoload :Public
25
+ end
26
+
27
+ end
@@ -0,0 +1,41 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class Base < OpenStack::Common
23
+
24
+ def self.site
25
+ if self == OpenStack::Nova::Compute::Base
26
+ Thread.current[:open_stack_nova_compute_site]
27
+ else
28
+ super
29
+ end
30
+ end
31
+
32
+ def self.site=(site)
33
+ super(site)
34
+ Thread.current[:open_stack_nova_compute_site] = @site
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,59 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class BaseDetail < Base
23
+
24
+ # Overrides ActiveResource::Base::collection_path to add /details to resource path for servers and
25
+ # to remove .<extension>
26
+ def self.collection_path(prefix_options = {}, query_options = nil)
27
+ check_prefix_options(prefix_options)
28
+
29
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
30
+ "#{prefix(prefix_options)}#{collection_name}/detail#{query_string(query_options)}"
31
+ end
32
+
33
+ def self.collection_path_create(prefix_options = {}, query_options = nil)
34
+ check_prefix_options(prefix_options)
35
+
36
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
37
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
38
+ end
39
+
40
+ def collection_path_create(options = nil)
41
+ self.class.collection_path_create(options || prefix_options)
42
+ end
43
+
44
+ protected
45
+
46
+ # Create (i.e., \save to the remote service) the \new resource.
47
+ def create
48
+ connection.post(collection_path_create, encode, self.class.headers).tap do |response|
49
+ self.id = id_from_response(response)
50
+ load_attributes_from_response(response)
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,56 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class Flavor < BaseDetail
23
+ schema do
24
+ attribute :name, :string
25
+ attribute :ram, :integer
26
+ attribute :disk, :integer
27
+ attribute :vcpus, :integer
28
+ attribute :rxtx_factor, :float
29
+ attribute :ephemeral_disk, :integer
30
+ end
31
+
32
+ validates :name, :presence => true, :format => {:with => /\A[\w\.\-]+\Z/}, :length => {:minimum => 2, :maximum => 255}
33
+ validates :ram, :presence => true, :numericality => {:greater_than_or_equal_to => 1, :only_integer => true}
34
+ validates :vcpus, :presence => true, :numericality => {:greater_than_or_equal_to => 1, :only_integer => true}
35
+ validates :disk, :presence => true, :numericality => {:greater_than_or_equal_to => 10, :only_integer => true}
36
+ validates :ephemeral_disk, :presence => false, :numericality => {:greater_than_or_equal_to => 10, :only_integer => true}
37
+
38
+ def self.find_all_by_name(name)
39
+ all.reject! { |flavor| flavor.name != name }
40
+ end
41
+
42
+ def self.find_by_name(name)
43
+ all.each { |flavor| return flavor if flavor.name == name }
44
+
45
+ nil
46
+ end
47
+
48
+ def ephemeral_disk
49
+ @attributes[:'OS-FLV-EXT-DATA:ephemeral'] || nil
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class FloatingIp < Base
23
+ self.collection_name = "os-floating-ips"
24
+ self.element_name = "floating_ip"
25
+
26
+ schema do
27
+ attribute :fixed_ip, :string
28
+ attribute :ip, :string
29
+ attribute :pool, :string
30
+ attribute :instance_id, :string
31
+ end
32
+
33
+ # Overload ActiveRecord::encode method
34
+ # Custom encoding to deal with openstack API
35
+ def encode(options={})
36
+ to_encode = {}
37
+ # Optional attributes (openstack will not accept empty attribute for update/create)
38
+ to_encode[:pool] = pool if pool.present?
39
+
40
+ to_encode.send("to_#{self.class.format.extension}", options)
41
+ end
42
+
43
+ def self.find_all_by_pool(pool)
44
+ all.reject! { |floating_ip| floating_ip.pool != pool }
45
+ end
46
+
47
+ def instance
48
+ Server.find(instance_id) if instance_id
49
+ end
50
+
51
+ # Assign the IP to a given server
52
+ # Params:
53
+ # ::server:: the server to assign the floating ip to
54
+ def assign!(server)
55
+ server.add_floating_ip(self)
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class FloatingIpPool < Base
23
+ self.collection_name = "os-floating-ip-pools"
24
+ self.element_name = "floating_ip_pool"
25
+
26
+ alias_attribute :id, :name
27
+
28
+ schema do
29
+ attribute :name, :string
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,76 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class Image < BaseDetail
23
+ schema do
24
+ attribute :name, :string
25
+ attribute :tenant_id, :string
26
+ attribute :user_id, :string
27
+ attribute :status, :string
28
+ attribute :progress, :string
29
+ attribute :min_disk, :string
30
+ attribute :min_ram, :string
31
+ attribute :updated_at, :datetime
32
+ attribute :created_at, :datetime
33
+ end
34
+
35
+ def initialize(attributes = {}, persisted = false)
36
+ attributes = attributes.with_indifferent_access
37
+ new_attributes = {
38
+ :id => attributes[:id],
39
+ :name => attributes[:name],
40
+ :min_ram => attributes[:minRam],
41
+ :min_disk => attributes[:minDisk],
42
+ :progress => attributes[:progress],
43
+ :status => attributes[:status],
44
+ :metadata => attributes[:metadata],
45
+ :server_id => attributes[:server].present? ? attributes[:server][:id] : nil,
46
+ :updated_at => attributes[:updated].present? ? DateTime.strptime(attributes[:updated], OpenStack::DATETIME_FORMAT) : nil,
47
+ :created_at => attributes[:created].present? ? DateTime.strptime(attributes[:created], OpenStack::DATETIME_FORMAT) : nil
48
+ }
49
+
50
+ super(new_attributes, persisted)
51
+ end
52
+
53
+ def self.find_all_by_name(name)
54
+ all.reject! { |image| image.name != name }
55
+ end
56
+
57
+ def self.find_by_name(name)
58
+ all.each { |image| return image if image.name == name }
59
+
60
+ nil
61
+ end
62
+
63
+ def server
64
+ Server.find(server_id) if server_id.present?
65
+ end
66
+
67
+ def image_type
68
+ metadata.image_type
69
+ rescue NoMethodError
70
+ 'image'
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,47 @@
1
+ # This file is part of the OpenStack-ActiveResource
2
+ #
3
+ # Copyright (C) 2012 Unidata S.p.A. (Davide Guerri - d.guerri@unidata.it)
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module OpenStack
19
+ module Nova
20
+ module Compute
21
+
22
+ class KeyPair < Base
23
+ self.collection_name = "os-keypairs"
24
+ self.element_name = "keypair"
25
+
26
+ schema do
27
+ attribute :name, :string
28
+ attribute :public_key, :string
29
+ attribute :private_key, :string
30
+ attribute :fingerprint, :string
31
+ end
32
+
33
+ def self.find_all_by_name(name)
34
+ all.reject! { |key_pair| key_pair.name != name }
35
+ end
36
+
37
+ def self.find_by_name(name)
38
+ all.each { |key_pair| return key_pair if key_pair.name == name }
39
+
40
+ nil
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end