openshift-origin-common 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYRIGHT +1 -0
- data/Gemfile +4 -0
- data/LICENSE +11 -0
- data/README.md +3 -0
- data/Rakefile +24 -0
- data/lib/openshift-origin-common.rb +33 -0
- data/lib/openshift-origin-common/config.rb +49 -0
- data/lib/openshift-origin-common/exceptions/oo_exception.rb +40 -0
- data/lib/openshift-origin-common/models/cartridge.rb +151 -0
- data/lib/openshift-origin-common/models/component.rb +109 -0
- data/lib/openshift-origin-common/models/component_ref.rb +24 -0
- data/lib/openshift-origin-common/models/connection.rb +20 -0
- data/lib/openshift-origin-common/models/connector.rb +22 -0
- data/lib/openshift-origin-common/models/group.rb +79 -0
- data/lib/openshift-origin-common/models/model.rb +209 -0
- data/lib/openshift-origin-common/models/profile.rb +187 -0
- data/lib/openshift-origin-common/models/scaling.rb +27 -0
- data/lib/openshift-origin-common/models/user_model.rb +99 -0
- data/openshift-origin-common.gemspec +23 -0
- data/rubygem-openshift-origin-common.spec +121 -0
- metadata +114 -0
data/COPYRIGHT
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copyright 2012 Red Hat, Inc. and/or its affiliates.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
you may not use this file except in compliance with the License.
|
3
|
+
You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
See the License for the specific language governing permissions and
|
11
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
Notice of Export Control Law
|
2
|
+
|
3
|
+
This software distribution includes cryptographic software that is subject to the U.S. Export Administration Regulations (the "*EAR*") and other U.S. and foreign laws and may not be exported, re-exported or transferred (a) to any country listed in Country Group E:1 in Supplement No. 1 to part 740 of the EAR (currently, Cuba, Iran, North Korea, Sudan & Syria); (b) to any prohibited destination or to any end user who has been prohibited from participating in U.S. export transactions by any federal agency of the U.S. government; or (c) for use in connection with the design, development or production of nuclear, chemical or biological weapons, or rocket systems, space launch vehicles, or sounding rockets, or unmanned air vehicle systems.You may not download this software or technical information if you are located in one of these countries or otherwise subject to these restrictions. You may not provide this software or technical information to individuals or entities located in one of these countries or otherwise subject to these restrictions. You are also responsible for compliance with foreign law requirements applicable to the import, export and use of this software and technical information.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
|
7
|
+
desc "Print environment to run from checkout - eval $( rake local_env | tail -n +1 )"
|
8
|
+
task :local_env do
|
9
|
+
pwd = Dir.pwd
|
10
|
+
puts "RUBYLIB='#{pwd}/lib/'; export RUBYLIB"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Unit tests"
|
14
|
+
Rake::TestTask.new(:test) do |t|
|
15
|
+
t.libs << File.expand_path('../lib', __FILE__)
|
16
|
+
t.libs << File.expand_path('../test', __FILE__)
|
17
|
+
t.libs << File.expand_path('../test/unit', __FILE__)
|
18
|
+
t.pattern = 'test/unit/**/*_test.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Generate RDoc"
|
22
|
+
task :doc do
|
23
|
+
sh "rdoc ."
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
|
19
|
+
require 'fileutils'
|
20
|
+
require 'getoptlong'
|
21
|
+
require 'json'
|
22
|
+
require "openshift-origin-common/config"
|
23
|
+
require "openshift-origin-common/models/model"
|
24
|
+
require "openshift-origin-common/models/user_model"
|
25
|
+
require "openshift-origin-common/exceptions/oo_exception"
|
26
|
+
require "openshift-origin-common/models/scaling"
|
27
|
+
require "openshift-origin-common/models/component_ref"
|
28
|
+
require "openshift-origin-common/models/group"
|
29
|
+
require "openshift-origin-common/models/connector"
|
30
|
+
require "openshift-origin-common/models/component"
|
31
|
+
require "openshift-origin-common/models/connection"
|
32
|
+
require "openshift-origin-common/models/profile"
|
33
|
+
require "openshift-origin-common/models/cartridge"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'parseconfig'
|
19
|
+
|
20
|
+
module OpenShift
|
21
|
+
class Config
|
22
|
+
CONF_DIR = '/etc/openshift/'
|
23
|
+
PLUGINS_DIR = File.join(CONF_DIR, 'plugins.d/')
|
24
|
+
NODE_CONF_FILE = File.join(CONF_DIR, 'node.conf')
|
25
|
+
|
26
|
+
def initialize(conf_path=NODE_CONF_FILE)
|
27
|
+
begin
|
28
|
+
@conf = ParseConfig.new(conf_path)
|
29
|
+
rescue Errno::EACCES => e
|
30
|
+
puts "Could not open config file #{conf_path}: #{e.message}"
|
31
|
+
exit 253
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def get(name, default=nil)
|
36
|
+
val = @conf.get_value(name)
|
37
|
+
val = default.to_s if (val.nil? and !default.nil?)
|
38
|
+
val.gsub!(/\\:/,":") if not val.nil?
|
39
|
+
val.gsub!(/[ \t]*#[^\n]*/,"") if not val.nil?
|
40
|
+
val = val[1..-2] if not val.nil? and val.start_with? "\""
|
41
|
+
val
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_bool(name, default=nil)
|
45
|
+
# !! is used to normalise the value to either a 1 (true) or a 0 (false).
|
46
|
+
!!(get(name, default) =~ /^(true|t|yes|y|1)$/i)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class OOException < StandardError
|
3
|
+
attr_accessor :code, :resultIO
|
4
|
+
|
5
|
+
def initialize(msg=nil, code=nil, resultIO=nil)
|
6
|
+
super(msg)
|
7
|
+
@code = code
|
8
|
+
@resultIO = resultIO
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class NodeException < OpenShift::OOException; end
|
13
|
+
class InvalidNodeException < NodeException
|
14
|
+
attr_accessor :server_identity
|
15
|
+
|
16
|
+
def initialize(msg=nil, code=nil, resultIO=nil, server_identity=nil)
|
17
|
+
super(msg, code, resultIO)
|
18
|
+
@server_identity = server_identity
|
19
|
+
end
|
20
|
+
end
|
21
|
+
class GearsException < Exception
|
22
|
+
attr_accessor :successful, :failed, :exception
|
23
|
+
|
24
|
+
def initialize(successful=nil, failed=nil, exception=nil)
|
25
|
+
@successful = successful
|
26
|
+
@failed = failed
|
27
|
+
@exception = exception
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class UserException < OpenShift::OOException; end
|
32
|
+
class UserKeyException < OpenShift::OOException; end
|
33
|
+
class AuthServiceException < OpenShift::OOException; end
|
34
|
+
class UserValidationException < OpenShift::OOException; end
|
35
|
+
class AccessDeniedException < UserValidationException; end
|
36
|
+
class DNSException < OpenShift::OOException; end
|
37
|
+
class DNSAlreadyExistsException < DNSException; end
|
38
|
+
class DNSNotFoundException < DNSException; end
|
39
|
+
class EstimatesException < OpenShift::OOException; end
|
40
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Cartridge < OpenShift::UserModel
|
3
|
+
attr_accessor :name, :version, :architecture, :display_name, :description, :vendor, :license,
|
4
|
+
:provides_feature, :requires_feature, :conflicts_feature, :requires, :default_profile,
|
5
|
+
:path, :profile_name_map, :license_url, :categories, :website, :suggests_feature,
|
6
|
+
:help_topics, :cart_data_def
|
7
|
+
exclude_attributes :profile_name_map
|
8
|
+
include_attributes :profiles
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
self.from_descriptor({"Name" => "unknown-cartridge"})
|
13
|
+
self.profile_name_map = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def all_capabilities
|
17
|
+
caps = self.provides_feature.dup
|
18
|
+
self.profiles.each do |v|
|
19
|
+
caps += v.provides
|
20
|
+
end
|
21
|
+
caps.uniq
|
22
|
+
end
|
23
|
+
|
24
|
+
def profiles=(data)
|
25
|
+
data.each do |value|
|
26
|
+
add_profile(value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def profiles(name=nil)
|
31
|
+
@profile_name_map = {} if @profile_name_map.nil?
|
32
|
+
if name.nil?
|
33
|
+
@profile_name_map.values
|
34
|
+
else
|
35
|
+
@profile_name_map[name]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_profile(profile)
|
40
|
+
profile_name_map_will_change!
|
41
|
+
profiles_will_change!
|
42
|
+
@profile_name_map = {} if @profile_name_map.nil?
|
43
|
+
if profile.class == Profile
|
44
|
+
@profile_name_map[profile.name] = profile
|
45
|
+
else
|
46
|
+
key = profile["name"]
|
47
|
+
@profile_name_map[key] = Profile.new
|
48
|
+
@profile_name_map[key].attributes=profile
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Search for a profile that provides specified capabilities
|
53
|
+
def find_profile(capability)
|
54
|
+
if capability.nil? || self.provides_feature.include?(capability)
|
55
|
+
return @profile_name_map[self.default_profile]
|
56
|
+
end
|
57
|
+
|
58
|
+
self.profiles.each do |p|
|
59
|
+
return p if p.provides.include? capability
|
60
|
+
end
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def from_descriptor(spec_hash={})
|
65
|
+
self.name = spec_hash["Name"]
|
66
|
+
self.version = spec_hash["Version"] || "0.0"
|
67
|
+
self.architecture = spec_hash["Architecture"] || "noarch"
|
68
|
+
self.display_name = spec_hash["Display-Name"] || "#{self.name}-#{self.version}-#{self.architecture}"
|
69
|
+
self.license = spec_hash["License"] || "unknown"
|
70
|
+
self.license_url = spec_hash["License-Url"] || ""
|
71
|
+
self.vendor = spec_hash["Vendor"] || "unknown"
|
72
|
+
self.description = spec_hash["Description"] || ""
|
73
|
+
self.provides_feature = spec_hash["Provides"] || []
|
74
|
+
self.requires_feature = spec_hash["Requires"] || []
|
75
|
+
self.conflicts_feature = spec_hash["Conflicts"] || []
|
76
|
+
self.requires = spec_hash["Native-Requires"] || []
|
77
|
+
self.categories = spec_hash["Categories"] || ["cartridge"]
|
78
|
+
self.website = spec_hash["Website"] || ""
|
79
|
+
self.suggests_feature = spec_hash["Suggests"] || []
|
80
|
+
self.help_topics = spec_hash["Help-Topics"] || {}
|
81
|
+
self.cart_data_def = spec_hash["Cart-Data"] || {}
|
82
|
+
|
83
|
+
self.provides_feature = [self.provides_feature] if self.provides_feature.class == String
|
84
|
+
self.requires_feature = [self.requires_feature] if self.requires_feature.class == String
|
85
|
+
self.conflicts_feature = [self.conflicts_feature] if self.conflicts_feature.class == String
|
86
|
+
self.requires = [self.requires] if self.requires.class == String
|
87
|
+
|
88
|
+
if spec_hash.has_key?("Profiles")
|
89
|
+
spec_hash["Profiles"].each do |pname, p|
|
90
|
+
profile = Profile.new.from_descriptor(p)
|
91
|
+
profile.name = pname
|
92
|
+
add_profile(profile)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
["Name", "Version", "Architecture", "DisplayName", "License",
|
96
|
+
"Provides", "Requires", "Conflicts", "Native-Requires"].each do |k|
|
97
|
+
spec_hash.delete(k)
|
98
|
+
end
|
99
|
+
p = Profile.new.from_descriptor(spec_hash)
|
100
|
+
p.name = "default"
|
101
|
+
p.generated = true
|
102
|
+
add_profile(p)
|
103
|
+
end
|
104
|
+
self.default_profile = spec_hash["Default-Profile"] || self.profiles.first.name
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_descriptor
|
109
|
+
h = {
|
110
|
+
"Name" => self.name,
|
111
|
+
"Display-Name" => self.display_name,
|
112
|
+
}
|
113
|
+
|
114
|
+
h["Architecture"] = self.architecture if self.architecture != "noarch"
|
115
|
+
h["Version"] = self.version if self.version != "0.0"
|
116
|
+
h["Description"] = self.description if self.description and !self.description.empty?
|
117
|
+
h["License"] = self.license if self.license and !self.license.empty? and self.license != "unknown"
|
118
|
+
h["License-Url"] = self.license_url if self.license_url and !self.license_url.empty?
|
119
|
+
h["Categories"] = self.categories if self.categories and !self.categories.empty?
|
120
|
+
h["Website"] = self.website if self.website and !self.website.empty?
|
121
|
+
h["Help-Topics"] = self.help_topics if self.help_topics and !self.help_topics.empty?
|
122
|
+
h["Cart-Data"] = self.cart_data_def if self.cart_data_def and !self.cart_data_def.empty?
|
123
|
+
|
124
|
+
h["Provides"] = self.provides_feature if self.provides_feature && !self.provides_feature.empty?
|
125
|
+
h["Requires"] = self.requires_feature if self.requires_feature && !self.requires_feature.empty?
|
126
|
+
h["Conflicts"] = self.conflicts_feature if self.conflicts_feature && !self.conflicts_feature.empty?
|
127
|
+
h["Suggests"] = self.suggests_feature if self.suggests_feature && !self.suggests_feature.empty?
|
128
|
+
h["Native-Requires"] = self.requires if self.requires && !self.requires.empty?
|
129
|
+
h["Vendor"] = self.vendor if self.vendor and !self.vendor.empty? and self.vendor != "unknown"
|
130
|
+
h["Default-Profile"] = self.default_profile if self.profile_name_map && !self.profile_name_map[self.default_profile].nil? &&
|
131
|
+
!self.profile_name_map[self.default_profile].generated
|
132
|
+
|
133
|
+
if self.profiles.length == 1 && self.profiles.first.generated
|
134
|
+
profile_h = self.profiles.first.to_descriptor
|
135
|
+
profile_h.delete("Name")
|
136
|
+
h.merge!(profile_h)
|
137
|
+
else
|
138
|
+
h["Profiles"] = {}
|
139
|
+
self.profiles.each do |v|
|
140
|
+
h["Profiles"][v.name] = v.to_descriptor
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
h
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_name_prefix
|
148
|
+
return "/cart-" + self.name
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Component < OpenShift::Model
|
3
|
+
attr_accessor :name, :publish_name_map, :subscribe_name_map, :generated, :depends, :depends_service
|
4
|
+
exclude_attributes :publish_name_map, :subscribe_name_map
|
5
|
+
include_attributes :publishes, :subscribes
|
6
|
+
|
7
|
+
def initialize(name=nil)
|
8
|
+
self.name = name
|
9
|
+
self.generated = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def publishes=(data)
|
13
|
+
data.each do |value|
|
14
|
+
add_publish(value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def publishes(name=nil)
|
19
|
+
@publish_name_map = {} if @publish_name_map.nil?
|
20
|
+
if name.nil?
|
21
|
+
@publish_name_map.values
|
22
|
+
else
|
23
|
+
@publish_name_map[name]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_publish(publish)
|
28
|
+
publish_name_map_will_change!
|
29
|
+
publishes_will_change!
|
30
|
+
@publish_name_map = {} if @publish_name_map.nil?
|
31
|
+
if publish.class == Connector
|
32
|
+
@publish_name_map[publish.name] = publish
|
33
|
+
else
|
34
|
+
key = publish["name"]
|
35
|
+
@publish_name_map[key] = Connector.new
|
36
|
+
@publish_name_map[key].attributes=publish
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def subscribes=(data)
|
41
|
+
data.each do |value|
|
42
|
+
add_subscribe(value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def subscribes(name=nil)
|
47
|
+
@subscribe_name_map = {} if @subscribe_name_map.nil?
|
48
|
+
if name.nil?
|
49
|
+
@subscribe_name_map.values
|
50
|
+
else
|
51
|
+
@subscribe_name_map[name]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_subscribe(subscribe)
|
56
|
+
subscribe_name_map_will_change!
|
57
|
+
subscribes_will_change!
|
58
|
+
@subscribe_name_map = {} if @subscribe_name_map.nil?
|
59
|
+
if subscribe.class == Connector
|
60
|
+
@subscribe_name_map[subscribe.name] = subscribe
|
61
|
+
else
|
62
|
+
key = subscribe["name"]
|
63
|
+
@subscribe_name_map[key] = Connector.new
|
64
|
+
@subscribe_name_map[key].attributes=subscribe
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def from_descriptor(spec_hash = {})
|
69
|
+
self.name = spec_hash["Name"] || "default"
|
70
|
+
if spec_hash["Publishes"]
|
71
|
+
spec_hash["Publishes"].each do |n, p|
|
72
|
+
conn = Connector.new(n).from_descriptor(p)
|
73
|
+
self.add_publish(conn)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if spec_hash["Subscribes"]
|
78
|
+
spec_hash["Subscribes"].each do |n,p|
|
79
|
+
conn = Connector.new(n).from_descriptor(p)
|
80
|
+
self.add_subscribe(conn)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
self.depends = spec_hash["Dependencies"] || []
|
85
|
+
self.depends_service = spec_hash["Service-Dependencies"] || []
|
86
|
+
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_descriptor
|
91
|
+
p = {}
|
92
|
+
self.publishes.each do |v|
|
93
|
+
p[v.name] = v.to_descriptor
|
94
|
+
end
|
95
|
+
|
96
|
+
s = {}
|
97
|
+
self.subscribes.each do |v|
|
98
|
+
s[v.name] = v.to_descriptor
|
99
|
+
end
|
100
|
+
|
101
|
+
h = {}
|
102
|
+
h["Publishes"] = p if self.publishes && !self.publishes.empty?
|
103
|
+
h["Subscribes"] = s if self.subscribes && !self.subscribes.empty?
|
104
|
+
h["Dependencies"] = self.depends if self.depends && !self.depends.empty?
|
105
|
+
h["Service-Dependencies"] = self.depends_service if self.depends_service && !self.depends_service.empty?
|
106
|
+
h
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class ComponentRef < OpenShift::Model
|
3
|
+
attr_accessor :name, :component
|
4
|
+
|
5
|
+
def initialize(name=nil)
|
6
|
+
self.name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_descriptor(spec_hash)
|
10
|
+
self.component = spec_hash
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_descriptor
|
15
|
+
self.component
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_name_prefix(profile)
|
19
|
+
comp_obj = profile.components(self.component)
|
20
|
+
return "" if comp_obj.generated
|
21
|
+
return "/comp-" + self.name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Connection < OpenShift::Model
|
3
|
+
attr_accessor :name, :components
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
self.name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_descriptor(spec_hash = {})
|
10
|
+
self.components = spec_hash["Components"]
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_descriptor
|
15
|
+
{
|
16
|
+
"Components" => self.components
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Connector < OpenShift::Model
|
3
|
+
attr_accessor :name, :type, :required
|
4
|
+
|
5
|
+
def initialize(name=nil)
|
6
|
+
self.name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_descriptor(spec_hash = {})
|
10
|
+
self.type = spec_hash["Type"]
|
11
|
+
self.required = spec_hash["Required"].to_s.downcase == "true" || false
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_descriptor
|
16
|
+
{
|
17
|
+
"Type" => self.type,
|
18
|
+
"Required" => self.required
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Group < OpenShift::Model
|
3
|
+
attr_accessor :name, :component_ref_name_map, :scaling, :generated
|
4
|
+
exclude_attributes :component_ref_name_map
|
5
|
+
include_attributes :component_refs
|
6
|
+
|
7
|
+
def initialize(name="default")
|
8
|
+
self.name = name
|
9
|
+
self.scaling = Scaling.new
|
10
|
+
self.generated = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def component_refs=(data)
|
14
|
+
data.each do |value|
|
15
|
+
add_component_ref(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def component_refs(name=nil)
|
20
|
+
@component_ref_name_map = {} if @component_ref_name_map.nil?
|
21
|
+
if name.nil?
|
22
|
+
@component_ref_name_map.values
|
23
|
+
else
|
24
|
+
@component_ref_name_map[name]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_component_ref(component_ref)
|
29
|
+
component_ref_name_map_will_change!
|
30
|
+
component_refs_will_change!
|
31
|
+
@component_ref_name_map = {} if @component_ref_name_map.nil?
|
32
|
+
if component_ref.class == ComponentRef
|
33
|
+
@component_ref_name_map[component_ref.name] = component_ref
|
34
|
+
else
|
35
|
+
key = component_ref["name"]
|
36
|
+
@component_ref_name_map[key] = ComponentRef.new
|
37
|
+
@component_ref_name_map[key].attributes=component_ref
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def scaling=(value)
|
42
|
+
scaling_will_change!
|
43
|
+
if value.kind_of?(Hash)
|
44
|
+
@scaling = Scaling.new
|
45
|
+
@scaling.attributes=value
|
46
|
+
else
|
47
|
+
@scaling = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def from_descriptor(spec_hash = {})
|
52
|
+
self.name = spec_hash["Name"] || "default"
|
53
|
+
if spec_hash.has_key?("Components")
|
54
|
+
spec_hash["Components"].each do |n,c|
|
55
|
+
self.add_component_ref(ComponentRef.new(n).from_descriptor(c))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
self.scaling.from_descriptor spec_hash["Scaling"] if spec_hash.has_key?("Scaling")
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_descriptor
|
63
|
+
components = {}
|
64
|
+
self.component_refs.each do |c|
|
65
|
+
components[c.name] = c.to_descriptor
|
66
|
+
end
|
67
|
+
|
68
|
+
{
|
69
|
+
"Components" => components,
|
70
|
+
"Scaling" => self.scaling.to_descriptor
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_name_prefix
|
75
|
+
return "" if self.generated
|
76
|
+
return "/group-" + self.name
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
module OpenShift
|
6
|
+
class Model
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
include ActiveModel::Validations
|
9
|
+
include ActiveModel::Serializers::JSON
|
10
|
+
self.include_root_in_json = false
|
11
|
+
include ActiveModel::Serializers::Xml
|
12
|
+
include ActiveModel::Dirty
|
13
|
+
include ActiveModel::Observing
|
14
|
+
include ActiveModel::AttributeMethods
|
15
|
+
include ActiveModel::Observing
|
16
|
+
include ActiveModel::Conversion
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@persisted = false
|
20
|
+
@new_record = true
|
21
|
+
@deleted = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_record?
|
25
|
+
@new_record
|
26
|
+
end
|
27
|
+
|
28
|
+
def persisted?
|
29
|
+
@persisted
|
30
|
+
end
|
31
|
+
|
32
|
+
def deleted?
|
33
|
+
@deleted
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.gen_uuid
|
37
|
+
File.open("/proc/sys/kernel/random/uuid", "r") do |file|
|
38
|
+
file.gets.strip.gsub("-","")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.attr_reader(*accessors)
|
43
|
+
@attribute_methods_generated = false
|
44
|
+
define_attribute_methods accessors
|
45
|
+
|
46
|
+
accessors.each do |m|
|
47
|
+
define_method(m) do
|
48
|
+
instance_variable_get("@#{m}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.attr_writer(*accessors)
|
54
|
+
@attribute_methods_generated = false
|
55
|
+
define_attribute_methods accessors
|
56
|
+
|
57
|
+
accessors.each do |m|
|
58
|
+
class_eval <<-EOF
|
59
|
+
def #{m}=(val)
|
60
|
+
#{m}_will_change! unless @#{m} == val
|
61
|
+
instance_variable_set("@#{m}",val)
|
62
|
+
end
|
63
|
+
EOF
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.attr_accessor(*accessors)
|
68
|
+
attr_reader(*accessors)
|
69
|
+
attr_writer(*accessors)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.primary_key(var_name)
|
73
|
+
@primary_key = var_name
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.exclude_attributes(*attributes)
|
77
|
+
@excludes_attributes = [] unless @excludes_attributes
|
78
|
+
@excludes_attributes += attributes
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.include_attributes(*attributes)
|
82
|
+
@includes_attributes = [] unless @includes_attributes
|
83
|
+
@includes_attributes += attributes
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.includes_attributes
|
87
|
+
@includes_attributes || []
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.excludes_attributes
|
91
|
+
@excludes_attributes || []
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.require_update_attributes(*attributes)
|
95
|
+
@requires_update_attributes = [] unless @requires_update_attributes
|
96
|
+
@requires_update_attributes += attributes
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.requires_update_attributes
|
100
|
+
#nil indicates all fields require updates
|
101
|
+
@requires_update_attributes
|
102
|
+
end
|
103
|
+
|
104
|
+
def attributes(should_convert_nested_models=false)
|
105
|
+
@attributes = {}
|
106
|
+
|
107
|
+
klass = self.class
|
108
|
+
var_names = self.instance_variable_names.map{|n| n[1..-1]}
|
109
|
+
while(klass != OpenShift::Model)
|
110
|
+
var_names += klass.includes_attributes.map{|n| n.to_s}
|
111
|
+
var_names -= ['attributes', 'changed_attributes', 'previously_changed', 'persisted', 'new_record', 'deleted', 'errors', 'validation_context']
|
112
|
+
var_names -= klass.excludes_attributes.map{|n| n.to_s}
|
113
|
+
klass = klass.superclass
|
114
|
+
end
|
115
|
+
|
116
|
+
var_names.each do |name|
|
117
|
+
#next if ['attributes', 'changed_attributes', 'previously_changed', 'persisted', 'new_record', 'deleted', 'errors', 'validation_context'].include? name
|
118
|
+
#next if self.class.excludes_attributes.include? name.to_sym
|
119
|
+
value = self.send(name.to_s)
|
120
|
+
if should_convert_nested_models
|
121
|
+
@attributes[name] = convert_nested_models(value)
|
122
|
+
else
|
123
|
+
@attributes[name] = value
|
124
|
+
end
|
125
|
+
end
|
126
|
+
@attributes
|
127
|
+
end
|
128
|
+
|
129
|
+
def attributes=(hash)
|
130
|
+
return nil unless hash
|
131
|
+
|
132
|
+
hash.each do |key,value|
|
133
|
+
self.send("#{key}=",value)
|
134
|
+
end
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
def reset_state
|
139
|
+
@new_record = false
|
140
|
+
@persisted = true
|
141
|
+
@deleted = false
|
142
|
+
@changed_attributes.clear if @changed_attributes
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.excludes_attributes
|
146
|
+
@excludes_attributes = [] unless @excludes_attributes
|
147
|
+
@excludes_attributes
|
148
|
+
end
|
149
|
+
|
150
|
+
def to_xml(options = {})
|
151
|
+
to_xml_opts = {:skip_types => true}
|
152
|
+
to_xml_opts.merge!(options.slice(:builder, :skip_instruct))
|
153
|
+
to_xml_opts[:root] = options[:tag_name] || self.class.name.underscore.gsub("_","-")
|
154
|
+
self.attributes.to_xml(to_xml_opts)
|
155
|
+
end
|
156
|
+
|
157
|
+
protected
|
158
|
+
|
159
|
+
def self.pk
|
160
|
+
@primary_key
|
161
|
+
end
|
162
|
+
|
163
|
+
def convert_nested_models(obj)
|
164
|
+
case obj
|
165
|
+
when OpenShift::Model
|
166
|
+
obj.attributes(true)
|
167
|
+
when Hash
|
168
|
+
convert_nested_models_in_hash(obj)
|
169
|
+
when Array
|
170
|
+
convert_nested_models_in_array(obj)
|
171
|
+
else
|
172
|
+
obj
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def convert_nested_models_in_hash(hash)
|
177
|
+
ret = {}
|
178
|
+
hash.each do |k,value|
|
179
|
+
case value
|
180
|
+
when OpenShift::Model
|
181
|
+
ret[k]=convert_nested_models(value)
|
182
|
+
when Hash
|
183
|
+
ret[k]=convert_nested_models_in_hash(value)
|
184
|
+
when Array
|
185
|
+
ret[k]=convert_nested_models_in_array(value)
|
186
|
+
else
|
187
|
+
ret[k]=value
|
188
|
+
end
|
189
|
+
end
|
190
|
+
ret
|
191
|
+
end
|
192
|
+
|
193
|
+
def convert_nested_models_in_array(arr)
|
194
|
+
arr.map do |value|
|
195
|
+
case value
|
196
|
+
when OpenShift::Model
|
197
|
+
convert_nested_models(value)
|
198
|
+
when Hash
|
199
|
+
convert_nested_models_in_hash(value)
|
200
|
+
when Array
|
201
|
+
convert_nested_models_in_array(value)
|
202
|
+
else
|
203
|
+
value
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Profile < OpenShift::Model
|
3
|
+
validates_presence_of :name, :groups
|
4
|
+
attr_accessor :name, :provides, :component_name_map, :group_name_map, :group_overrides,
|
5
|
+
:connection_name_map, :property_overrides, :service_overrides,
|
6
|
+
:start_order, :stop_order, :configure_order, :generated
|
7
|
+
exclude_attributes :component_name_map, :group_name_map, :connection_name_map
|
8
|
+
include_attributes :components, :groups, :connections
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.generated = false
|
12
|
+
self.provides = []
|
13
|
+
self.group_overrides = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def components=(data)
|
17
|
+
data.each {|comp| add_component(comp)}
|
18
|
+
end
|
19
|
+
|
20
|
+
def groups=(data)
|
21
|
+
data.each {|group| add_group(group)}
|
22
|
+
end
|
23
|
+
|
24
|
+
def connections=(data)
|
25
|
+
data.each {|conn| add_connection(conn)}
|
26
|
+
end
|
27
|
+
|
28
|
+
def components(name=nil)
|
29
|
+
@component_name_map = {} if @component_name_map.nil?
|
30
|
+
if name.nil?
|
31
|
+
@component_name_map.values
|
32
|
+
else
|
33
|
+
@component_name_map[name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def groups(name=nil)
|
38
|
+
@group_name_map = {} if @group_name_map.nil?
|
39
|
+
if name.nil?
|
40
|
+
@group_name_map.values
|
41
|
+
else
|
42
|
+
@group_name_map[name]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def connections(name=nil)
|
47
|
+
@connection_name_map = {} if @connection_name_map.nil?
|
48
|
+
if name.nil?
|
49
|
+
@connection_name_map.values
|
50
|
+
else
|
51
|
+
@connection_name_map[name]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_component(comp)
|
56
|
+
component_name_map_will_change!
|
57
|
+
@component_name_map = {} if @component_name_map.nil?
|
58
|
+
if comp.class == Component
|
59
|
+
@component_name_map[comp.name] = comp
|
60
|
+
else
|
61
|
+
key = comp["name"]
|
62
|
+
@component_name_map[key] = Component.new(key)
|
63
|
+
@component_name_map[key].attributes=comp
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_group(group)
|
68
|
+
group_name_map_will_change!
|
69
|
+
@group_name_map = {} if @group_name_map.nil?
|
70
|
+
if group.class == Group
|
71
|
+
@group_name_map[group.name] = group
|
72
|
+
else
|
73
|
+
key = group["name"]
|
74
|
+
@group_name_map[key] = Group.new(key)
|
75
|
+
@group_name_map[key].attributes=group
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_connection(conn)
|
80
|
+
connection_name_map_will_change!
|
81
|
+
@connection_name_map = {} if @connection_name_map.nil?
|
82
|
+
if conn.class == Connection
|
83
|
+
@connection_name_map[conn.name] = conn
|
84
|
+
else
|
85
|
+
key = conn["name"]
|
86
|
+
@connection_name_map[key] = Connection.new(key)
|
87
|
+
@connection_name_map[key].attributes=conn
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def from_descriptor(spec_hash = {})
|
92
|
+
self.name = spec_hash["Name"] || "default"
|
93
|
+
self.provides = spec_hash["Provides"] || []
|
94
|
+
self.start_order = spec_hash["Start-Order"] || []
|
95
|
+
self.stop_order = spec_hash["Stop-Order"] || []
|
96
|
+
self.configure_order = spec_hash["Configure-Order"] || []
|
97
|
+
|
98
|
+
#fixup user data. provides, start_order, start_order, configure_order bust be arrays
|
99
|
+
self.provides = [self.provides] if self.provides.class == String
|
100
|
+
self.start_order = [self.start_order] if self.start_order.class == String
|
101
|
+
self.stop_order = [self.stop_order] if self.stop_order.class == String
|
102
|
+
self.configure_order = [self.configure_order] if self.configure_order.class == String
|
103
|
+
|
104
|
+
if spec_hash.has_key?("Components")
|
105
|
+
spec_hash["Components"].each do |cname, c|
|
106
|
+
comp = Component.new.from_descriptor(c)
|
107
|
+
comp.name = cname
|
108
|
+
add_component(comp)
|
109
|
+
end
|
110
|
+
else
|
111
|
+
comp_spec_hash = spec_hash.dup.delete_if{|k,v| !["Publishes", "Subscribes"].include?(k) }
|
112
|
+
c = Component.new.from_descriptor(comp_spec_hash)
|
113
|
+
c.generated = true
|
114
|
+
add_component(c)
|
115
|
+
end
|
116
|
+
|
117
|
+
if spec_hash.has_key?("Groups")
|
118
|
+
spec_hash["Groups"].each do |gname, g|
|
119
|
+
group = Group.new.from_descriptor(g)
|
120
|
+
group.name = gname
|
121
|
+
add_group(group)
|
122
|
+
end
|
123
|
+
else
|
124
|
+
group = Group.new
|
125
|
+
self.components.each do |c|
|
126
|
+
group.add_component_ref(ComponentRef.new(c.name).from_descriptor(c.name))
|
127
|
+
end
|
128
|
+
if spec_hash.has_key?("Scaling")
|
129
|
+
group.scaling = Scaling.new.from_descriptor(spec_hash["Scaling"])
|
130
|
+
end
|
131
|
+
group.generated = true
|
132
|
+
add_group(group)
|
133
|
+
end
|
134
|
+
|
135
|
+
if spec_hash.has_key?("Connections")
|
136
|
+
spec_hash["Connections"].each do |n,c|
|
137
|
+
conn = Connection.new(n).from_descriptor(c)
|
138
|
+
add_connection(conn)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
self.group_overrides = [] if self.group_overrides.nil?
|
143
|
+
if spec_hash.has_key?("GroupOverrides")
|
144
|
+
spec_hash["GroupOverrides"].each do |go|
|
145
|
+
# each group override is a list
|
146
|
+
group_overrides << go.dup
|
147
|
+
end
|
148
|
+
end
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
152
|
+
def to_descriptor
|
153
|
+
h = {}
|
154
|
+
h["Provides"] = @provides unless @provides.nil? || @provides.empty?
|
155
|
+
h["Start-Order"] = @start_order unless @start_order.nil? || @start_order.empty?
|
156
|
+
h["Stop-Order"] = @stop_order unless @stop_order.nil? || @stop_order.empty?
|
157
|
+
h["Configure-Order"] = @configure_order unless @configure_order.nil? || @configure_order.empty?
|
158
|
+
|
159
|
+
if self.components.length == 1 && self.components.first.generated
|
160
|
+
comp_h = self.components.first.to_descriptor
|
161
|
+
comp_h.delete("Name")
|
162
|
+
h.merge!(comp_h)
|
163
|
+
else
|
164
|
+
h["Components"] = {}
|
165
|
+
self.components.each do |v|
|
166
|
+
h["Components"][v.name] = v.to_descriptor
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
if self.groups.length == 1 && self.groups.first.generated
|
171
|
+
h["Scaling"] = self.groups.first.scaling.to_descriptor if !self.groups.first.scaling.generated
|
172
|
+
else
|
173
|
+
h["Groups"] = {}
|
174
|
+
self.groups.each do |v|
|
175
|
+
h["Groups"][v.name] = v.to_descriptor
|
176
|
+
end
|
177
|
+
end
|
178
|
+
if !self.connections.empty?
|
179
|
+
h["Connections"] = {}
|
180
|
+
self.connections.each do |v|
|
181
|
+
h["Connections"][v.name] = v.to_descriptor
|
182
|
+
end
|
183
|
+
end
|
184
|
+
h
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class Scaling < OpenShift::Model
|
3
|
+
attr_accessor :min, :max, :generated
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.min = 1
|
7
|
+
self.max = -1
|
8
|
+
end
|
9
|
+
|
10
|
+
def generated
|
11
|
+
self.min == 1 && self.max == -1
|
12
|
+
end
|
13
|
+
|
14
|
+
def from_descriptor(spec_hash = {})
|
15
|
+
self.min = spec_hash["Min"].to_i || 1
|
16
|
+
self.max = spec_hash["Max"].to_i || -1
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_descriptor
|
21
|
+
{
|
22
|
+
"Min" => self.min,
|
23
|
+
"Max" => self.max
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module OpenShift
|
2
|
+
class UserModel < Model
|
3
|
+
|
4
|
+
def initialize()
|
5
|
+
super()
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.find(login, id)
|
9
|
+
hash = DataStore.instance.find(self.name,login,id)
|
10
|
+
return nil unless hash
|
11
|
+
|
12
|
+
hash_to_obj(hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_by_uuid(uuid)
|
16
|
+
hash = DataStore.instance.find_by_uuid(self.name,uuid)
|
17
|
+
return nil unless hash
|
18
|
+
|
19
|
+
hash_to_obj(hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_all(login, opts=nil, &block)
|
23
|
+
hash_list = DataStore.instance.find_all(self.name, login, opts, &block)
|
24
|
+
unless block_given?
|
25
|
+
return hash_list if hash_list.empty?
|
26
|
+
hash_list.map! do |hash|
|
27
|
+
hash_to_obj(hash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(login)
|
33
|
+
id_var = self.class.pk || "uuid"
|
34
|
+
DataStore.instance.delete(self.class.name, login, instance_variable_get("@#{id_var}"))
|
35
|
+
end
|
36
|
+
|
37
|
+
def save(login)
|
38
|
+
id_var = self.class.pk || "uuid"
|
39
|
+
if persisted?
|
40
|
+
if self.class.requires_update_attributes
|
41
|
+
changed_attrs = {}
|
42
|
+
unless changes.empty?
|
43
|
+
changes.each do |key, value|
|
44
|
+
value = value[1]
|
45
|
+
unless self.class.excludes_attributes.include? key.to_sym
|
46
|
+
extract_value(changed_attrs, key, value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
self.class.requires_update_attributes.each do |key|
|
51
|
+
key = key.to_s
|
52
|
+
value = instance_variable_get("@#{key}")
|
53
|
+
extract_value(changed_attrs, key, value)
|
54
|
+
end
|
55
|
+
DataStore.instance.save(self.class.name, login, instance_variable_get("@#{id_var}"), changed_attrs) unless changed_attrs.empty?
|
56
|
+
else
|
57
|
+
DataStore.instance.save(self.class.name, login, instance_variable_get("@#{id_var}"), self.attributes(true))
|
58
|
+
end
|
59
|
+
else
|
60
|
+
DataStore.instance.create(self.class.name, login, instance_variable_get("@#{id_var}"), self.attributes(true))
|
61
|
+
end
|
62
|
+
@previously_changed = changes
|
63
|
+
@changed_attributes.clear
|
64
|
+
@new_record = false
|
65
|
+
@persisted = true
|
66
|
+
@deleted = false
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def extract_value(changed_attrs, key, value)
|
73
|
+
if value.is_a?(Array) && value.length > 0 && value.first.kind_of?(OpenShift::Model)
|
74
|
+
value.map! do |model|
|
75
|
+
model.attributes(true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
if value.kind_of?(OpenShift::Model)
|
79
|
+
changed_attrs[key] = value.attributes(true)
|
80
|
+
else
|
81
|
+
changed_attrs[key] = value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.json_to_obj(json)
|
86
|
+
obj = self.new.from_json(json)
|
87
|
+
obj.reset_state
|
88
|
+
obj
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.hash_to_obj(hash)
|
92
|
+
obj = self.new
|
93
|
+
obj.attributes=hash
|
94
|
+
obj.reset_state
|
95
|
+
obj
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# OS independent path locations
|
2
|
+
lib_dir = File.join(File.join("lib", "**"), "*")
|
3
|
+
test_dir = File.join(File.join("test", "**"), "*")
|
4
|
+
spec_file = "rubygem-openshift-origin-common.spec"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "openshift-origin-common"
|
8
|
+
s.version = `rpm -q --define 'rhel 7' --qf "%{version}\n" --specfile #{spec_file}`.split[0]
|
9
|
+
s.license = `rpm -q --define 'rhel 7' --qf "%{license}\n" --specfile #{spec_file}`.split[0]
|
10
|
+
s.authors = ["Krishna Raman"]
|
11
|
+
s.email = ["kraman@gmail.com"]
|
12
|
+
s.homepage = `rpm -q --define 'rhel 7' --qf "%{url}\n" --specfile #{spec_file}`.split[0]
|
13
|
+
s.summary = `rpm -q --define 'rhel 7' --qf "%{description}\n" --specfile #{spec_file}`.split[0]
|
14
|
+
s.description = `rpm -q --define 'rhel 7' --qf "%{description}\n" --specfile #{spec_file}`.split[0]
|
15
|
+
|
16
|
+
s.rubyforge_project = "openshift-origin-common"
|
17
|
+
s.files = Dir[lib_dir] + Dir[test_dir]
|
18
|
+
s.files += %w(README.md Rakefile Gemfile rubygem-openshift-origin-common.spec openshift-origin-common.gemspec LICENSE COPYRIGHT)
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency("json")
|
22
|
+
s.add_dependency("activemodel")
|
23
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
%if 0%{?fedora}%{?rhel} <= 6
|
2
|
+
%global scl ruby193
|
3
|
+
%global scl_prefix ruby193-
|
4
|
+
%endif
|
5
|
+
%{!?scl:%global pkg_name %{name}}
|
6
|
+
%{?scl:%scl_package rubygem-%{gem_name}}
|
7
|
+
%global gem_name openshift-origin-common
|
8
|
+
%global rubyabi 1.9.1
|
9
|
+
|
10
|
+
Summary: Cloud Development Common
|
11
|
+
Name: rubygem-%{gem_name}
|
12
|
+
Version: 1.2.3
|
13
|
+
Release: 1%{?dist}
|
14
|
+
Group: Development/Languages
|
15
|
+
License: ASL 2.0
|
16
|
+
URL: http://openshift.redhat.com
|
17
|
+
Source0: rubygem-%{gem_name}-%{version}.tar.gz
|
18
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
19
|
+
Requires: %{?scl:%scl_prefix}ruby
|
20
|
+
Requires: %{?scl:%scl_prefix}rubygems
|
21
|
+
Requires: %{?scl:%scl_prefix}rubygem(activemodel)
|
22
|
+
Requires: %{?scl:%scl_prefix}rubygem(json)
|
23
|
+
%if 0%{?rhel}
|
24
|
+
Requires: openshift-origin-util-scl
|
25
|
+
%endif
|
26
|
+
%if 0%{?fedora}
|
27
|
+
Requires: openshift-origin-util
|
28
|
+
%endif
|
29
|
+
%if 0%{?fedora}%{?rhel} <= 6
|
30
|
+
BuildRequires: ruby193-build
|
31
|
+
BuildRequires: scl-utils-build
|
32
|
+
%endif
|
33
|
+
BuildRequires: %{?scl:%scl_prefix}ruby(abi) = %{rubyabi}
|
34
|
+
BuildRequires: %{?scl:%scl_prefix}ruby
|
35
|
+
BuildRequires: %{?scl:%scl_prefix}rubygems
|
36
|
+
BuildRequires: %{?scl:%scl_prefix}rubygems-devel
|
37
|
+
BuildRequires: %{?scl:%scl_prefix}rubygem-yard
|
38
|
+
BuildArch: noarch
|
39
|
+
Provides: rubygem(%{gem_name}) = %version
|
40
|
+
Obsoletes: rubygem-stickshift-common
|
41
|
+
|
42
|
+
%package doc
|
43
|
+
Summary: Cloud Development Common Library Documentation
|
44
|
+
|
45
|
+
%description
|
46
|
+
This contains the Cloud Development Common packaged as a rubygem.
|
47
|
+
|
48
|
+
%description doc
|
49
|
+
This contains the Cloud Development Common packaged as a ruby site library
|
50
|
+
documentation files.
|
51
|
+
|
52
|
+
%prep
|
53
|
+
%setup -q
|
54
|
+
|
55
|
+
%build
|
56
|
+
mkdir -p ./%{gem_dir}
|
57
|
+
|
58
|
+
%{?scl:scl enable %scl - << \EOF}
|
59
|
+
gem build %{gem_name}.gemspec
|
60
|
+
export CONFIGURE_ARGS="--with-cflags='%{optflags}'"
|
61
|
+
gem install -V \
|
62
|
+
--local \
|
63
|
+
--install-dir ./%{gem_dir} \
|
64
|
+
--bindir ./%{_bindir} \
|
65
|
+
--force \
|
66
|
+
--rdoc \
|
67
|
+
%{gem_name}-%{version}.gem
|
68
|
+
%{?scl:EOF}
|
69
|
+
|
70
|
+
%install
|
71
|
+
mkdir -p %{buildroot}%{gem_dir}
|
72
|
+
cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}/
|
73
|
+
|
74
|
+
%clean
|
75
|
+
rm -rf %{buildroot}
|
76
|
+
|
77
|
+
%files
|
78
|
+
%dir %{gem_instdir}
|
79
|
+
%doc %{gem_instdir}/LICENSE
|
80
|
+
%doc %{gem_instdir}/COPYRIGHT
|
81
|
+
%doc %{gem_instdir}/.yardoc
|
82
|
+
%doc %{gem_instdir}/Gemfile
|
83
|
+
%doc %{gem_instdir}/Rakefile
|
84
|
+
%doc %{gem_instdir}/README.md
|
85
|
+
%doc %{gem_instdir}/%{gem_name}.gemspec
|
86
|
+
%{gem_spec}
|
87
|
+
%{gem_libdir}
|
88
|
+
|
89
|
+
%exclude %{gem_cache}
|
90
|
+
%exclude %{gem_instdir}/rubygem-%{gem_name}.spec
|
91
|
+
|
92
|
+
%files doc
|
93
|
+
%doc %{gem_docdir}
|
94
|
+
|
95
|
+
%changelog
|
96
|
+
* Wed Dec 05 2012 Adam Miller <admiller@redhat.com> 1.2.3-1
|
97
|
+
- updated gemspecs so they work with scl rpm spec files. (tdawson@redhat.com)
|
98
|
+
|
99
|
+
* Thu Nov 29 2012 Adam Miller <admiller@redhat.com> 1.2.2-1
|
100
|
+
- fix require for fedora (dmcphers@redhat.com)
|
101
|
+
- add util package for oo-ruby (dmcphers@redhat.com)
|
102
|
+
|
103
|
+
* Sat Nov 17 2012 Adam Miller <admiller@redhat.com> 1.2.1-1
|
104
|
+
- bump_minor_versions for sprint 21 (admiller@redhat.com)
|
105
|
+
|
106
|
+
* Thu Nov 15 2012 Adam Miller <admiller@redhat.com> 1.1.4-1
|
107
|
+
- Fix for bug# 876516 (rpenta@redhat.com)
|
108
|
+
- Fix bug# 876124: caused due to ruby 1.8 to 1.9 upgrade (rpenta@redhat.com)
|
109
|
+
|
110
|
+
* Wed Nov 14 2012 Adam Miller <admiller@redhat.com> 1.1.3-1
|
111
|
+
- remove %%prep steps that add gem pre-processing since we're using a .tar.gz
|
112
|
+
(admiller@redhat.com)
|
113
|
+
|
114
|
+
* Wed Nov 14 2012 Adam Miller <admiller@redhat.com> 1.1.2-1
|
115
|
+
- getting specs up to 1.9 sclized (dmcphers@redhat.com)
|
116
|
+
|
117
|
+
* Thu Nov 08 2012 Adam Miller <admiller@redhat.com> 1.1.1-1
|
118
|
+
- Bumping specs to at least 1.1 (dmcphers@redhat.com)
|
119
|
+
|
120
|
+
* Tue Oct 30 2012 Adam Miller <admiller@redhat.com> 1.0.1-1
|
121
|
+
- bumping specs to at least 1.0.0 (dmcphers@redhat.com)
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openshift-origin-common
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 3
|
10
|
+
version: 1.2.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Krishna Raman
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-12-05 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activemodel
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: This
|
50
|
+
email:
|
51
|
+
- kraman@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- lib/openshift-origin-common/config.rb
|
60
|
+
- lib/openshift-origin-common/models/user_model.rb
|
61
|
+
- lib/openshift-origin-common/models/component_ref.rb
|
62
|
+
- lib/openshift-origin-common/models/model.rb
|
63
|
+
- lib/openshift-origin-common/models/scaling.rb
|
64
|
+
- lib/openshift-origin-common/models/connector.rb
|
65
|
+
- lib/openshift-origin-common/models/component.rb
|
66
|
+
- lib/openshift-origin-common/models/profile.rb
|
67
|
+
- lib/openshift-origin-common/models/connection.rb
|
68
|
+
- lib/openshift-origin-common/models/cartridge.rb
|
69
|
+
- lib/openshift-origin-common/models/group.rb
|
70
|
+
- lib/openshift-origin-common/exceptions/oo_exception.rb
|
71
|
+
- lib/openshift-origin-common.rb
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- Gemfile
|
75
|
+
- rubygem-openshift-origin-common.spec
|
76
|
+
- openshift-origin-common.gemspec
|
77
|
+
- LICENSE
|
78
|
+
- COPYRIGHT
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://openshift.redhat.com
|
81
|
+
licenses:
|
82
|
+
- ASL
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project: openshift-origin-common
|
109
|
+
rubygems_version: 1.3.7
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: This
|
113
|
+
test_files: []
|
114
|
+
|