openstack_activeresource 0.1.12 → 0.1.13

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.
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@ Command line:
17
17
 
18
18
  Or in bundler Gemfile:
19
19
 
20
- gem "openstack_activeresource", "~> 0.1.8"
20
+ gem "openstack_activeresource", "~> 0.1.12"
21
21
 
22
22
  == Sample usages
23
23
 
@@ -63,7 +63,7 @@ Or in bundler Gemfile:
63
63
  member_role = OpenStack::Keystone::Admin::Role.find_by_name "memberRole"
64
64
  new_tenant.add_role_to_user member_role, new_user
65
65
 
66
- === List image index from Nova
66
+ === Image index from Nova
67
67
 
68
68
  require 'openstack_activeresource'
69
69
 
@@ -143,6 +143,20 @@ Or in bundler Gemfile:
143
143
  printf "Name: %s, Id: %s, Ram: %5i, Disk: %3i (Ephemeral: %3i), vCPU: %2i\n", f.name.center(15), f.id.center(20), f.ram, f.disk, f.ephemeral_disk, f.vcpus
144
144
  }
145
145
 
146
+ # Get flavors that meet the given constraints
147
+ flavors = OpenStack::Nova::Compute::Flavor.find_by_constraints( :ram => 2048, :vcpus => 4, :disk => 20 )
148
+
149
+ flavors.each { |f|
150
+ printf "Name: %s, Id: %s, Ram: %5i, Disk: %3i (Ephemeral: %3i), vCPU: %2i\n", f.name.center(15), f.id.center(20), f.ram, f.disk, f.ephemeral_disk, f.vcpus
151
+ }
152
+
153
+ # Get available flavors that can be used for a given image
154
+ flavors = OpenStack::Nova::Compute::Flavor.applicable_for_image( OpenStack::Nova::Compute::Image.all.last )
155
+
156
+ flavors.each { |f|
157
+ printf "Name: %s, Id: %s, Ram: %5i, Disk: %3i (Ephemeral: %3i), vCPU: %2i\n", f.name.center(15), f.id.center(20), f.ram, f.disk, f.ephemeral_disk, f.vcpus
158
+ }
159
+
146
160
  === Create a flavor (requires 'admin' role)
147
161
 
148
162
  require 'openstack_activeresource'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -36,7 +36,7 @@ module OpenStack
36
36
  validates :ephemeral_disk, :presence => false, :numericality => {:greater_than_or_equal_to => 10, :only_integer => true}
37
37
 
38
38
  def self.find_all_by_name(name)
39
- all.reject! { |flavor| flavor.name != name }
39
+ all.reject { |flavor| flavor.name != name }
40
40
  end
41
41
 
42
42
  def self.find_by_name(name)
@@ -45,6 +45,23 @@ module OpenStack
45
45
  nil
46
46
  end
47
47
 
48
+ def self.find_by_constraints(constraints = {})
49
+ constraints = constraints.with_indifferent_access
50
+ constraints[:ram] ||= -1.0/0.0
51
+ constraints[:vcpus] ||= -1.0/0.0
52
+ constraints[:disk] ||= -1.0/0.0
53
+
54
+ all.select { |flavor| flavor.ram >= constraints[:ram] and flavor.vcpus >= constraints[:vcpus] and flavor.disk >= constraints[:disk] }
55
+ end
56
+
57
+ def self.applicable_for_image(image)
58
+ constraints = {}
59
+ constraints[:ram] = image.min_ram if image.min_ram > 0
60
+ constraints[:disk] = image.min_disk if image.min_disk > 0
61
+
62
+ find_by_constraints constraints
63
+ end
64
+
48
65
  def ephemeral_disk
49
66
  @attributes[:'OS-FLV-EXT-DATA:ephemeral'] || nil
50
67
  end
@@ -106,7 +106,7 @@ module OpenStack
106
106
  }
107
107
 
108
108
  # Optional attributes (openstack will not accept empty attribute for update/create)
109
- to_encode[:server][:user_data] = Base64.encode64(user_data) if user_data.present?
109
+ to_encode[:server][:user_data] = Base64.strict_encode64(user_data) if user_data.present?
110
110
  to_encode[:server][:key_name] = key_pair_id if key_pair_id.present?
111
111
  to_encode[:server][:security_groups] = security_groups.map { |sg| {:name => sg.name} }
112
112
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "openstack_activeresource"
8
- s.version = "0.1.12"
8
+ s.version = "0.1.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Davide Guerri"]
12
- s.date = "2013-01-21"
12
+ s.date = "2013-01-25"
13
13
  s.description = "OpenStack Ruby and RoR bindings implemented with ActiveResource - See also http://www.unicloud.it"
14
14
  s.email = "d.guerri@rd.unidata.it"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstack_activeresource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-21 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -210,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  segments:
212
212
  - 0
213
- hash: 2210907143149423611
213
+ hash: -506182676093724300
214
214
  required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  none: false
216
216
  requirements: