forj 0.0.48 → 1.0.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.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/bin/forj +59 -17
- data/lib/appinit.rb +2 -0
- data/lib/build_tmpl/bootstrap_build.sh +145 -0
- data/lib/build_tmpl/write-mime-multipart.py +128 -0
- data/lib/connection.rb +6 -8
- data/lib/defaults.yaml +130 -46
- data/lib/down.rb +1 -3
- data/{spec/yaml_parse_spec.rb → lib/forj/ForjCli.rb} +22 -0
- data/lib/forj/ForjCore.rb +111 -0
- data/lib/forj/process/ForjProcess.rb +623 -0
- data/lib/forj-account.rb +3 -380
- data/lib/forj-config.rb +6 -6
- data/lib/lib-forj/lib/core/core.rb +1687 -0
- data/lib/lib-forj/lib/core/definition.rb +441 -0
- data/lib/lib-forj/lib/core/definition_internal.rb +306 -0
- data/lib/lib-forj/lib/core_process/CloudProcess.rb +311 -0
- data/lib/lib-forj/lib/core_process/global_process.rb +403 -0
- data/lib/lib-forj/lib/core_process/network_process.rb +606 -0
- data/lib/lib-forj/lib/lib-forj.rb +37 -0
- data/lib/lib-forj/lib/providers/hpcloud/Hpcloud.rb +406 -0
- data/lib/lib-forj/lib/providers/hpcloud/compute.rb +108 -0
- data/lib/lib-forj/lib/providers/hpcloud/network.rb +107 -0
- data/lib/lib-forj/lib/providers/hpcloud/security_groups.rb +67 -0
- data/lib/lib-forj/lib/providers/templates/compute.rb +42 -0
- data/lib/lib-forj/lib/providers/templates/core.rb +61 -0
- data/lib/{yaml_parse.rb → lib-forj/lib/providers/templates/network.rb} +14 -26
- data/lib/log.rb +12 -1
- data/lib/repositories.rb +0 -6
- data/lib/ssh.rb +18 -15
- metadata +35 -6
- data/lib/boot.rb +0 -263
- data/lib/setup.rb +0 -45
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# This file is given as an example.
|
18
|
+
|
19
|
+
class Mycloud # This class is automatically derived from ForjCloudBase and ForjProcess
|
20
|
+
|
21
|
+
def provider_compute_new
|
22
|
+
# My fog connection
|
23
|
+
# hget_cloudObjMapping() is a ForjCloudBase function which will build a
|
24
|
+
# hash from data required with needed mapped keys(see core.rb)
|
25
|
+
Fog::Compute.new({:provider => :mycloud}.merge(hget_cloudObjMapping()))
|
26
|
+
|
27
|
+
# If you do not want to get data mapped automatically, you can use
|
28
|
+
# @oForjAccount.get()
|
29
|
+
# This means in following declaration in your core.rb:
|
30
|
+
# obj_needs(:data, :<CloudDataKey},{:mapping => :<MyCloudKeyMapped>})
|
31
|
+
# can be updated by removing the mapping => <Value>
|
32
|
+
Fog::Compute.new({
|
33
|
+
:provider => :mycloud,
|
34
|
+
:user => @oForjAccount.get(:account_id),
|
35
|
+
:pwd => @oForjAccount.get(:account_key),
|
36
|
+
:auth_uri => @oForjAccount.get(:auth_uri),
|
37
|
+
:project => @oForjAccount.get(:tenant),
|
38
|
+
:compute_service => @oForjAccount.get(:compute),
|
39
|
+
})
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
# This file is given as an example.
|
19
|
+
|
20
|
+
require File.join($PROVIDER_PATH, "compute.rb")
|
21
|
+
require File.join($PROVIDER_PATH, "network.rb")
|
22
|
+
|
23
|
+
# Defines Meta MyCloud object
|
24
|
+
class Mycloud
|
25
|
+
|
26
|
+
# Defines Object structure and function stored on the Hpcloud class object.
|
27
|
+
|
28
|
+
# ForjCloud has a list of predefined object, like compute_connection, network, ...
|
29
|
+
# See lib/providers/core/cloud_data_pref.rb
|
30
|
+
|
31
|
+
# Compute Object
|
32
|
+
define_obj :compute_connection
|
33
|
+
# Defines Data used by compute.
|
34
|
+
obj_needs(:data, :account_id, { :mapping => :user})
|
35
|
+
obj_needs(:data, :account_key, { :mapping => :pwd})
|
36
|
+
obj_needs(:data, :auth_uri, { :mapping => :auth_uri})
|
37
|
+
obj_needs(:data, :tenant, { :mapping => :project})
|
38
|
+
obj_needs(:data, :compute, { :mapping => :compute_service})
|
39
|
+
|
40
|
+
define_obj :network_connection
|
41
|
+
obj_needs(:data, :account_id, { :mapping => :user})
|
42
|
+
obj_needs(:data, :account_key, { :mapping => :pwd})
|
43
|
+
obj_needs(:data, :auth_uri, { :mapping => :auth_uri})
|
44
|
+
obj_needs(:data, :tenant, { :mapping => :project})
|
45
|
+
obj_needs(:data, :network, { :mapping => :network_service})
|
46
|
+
|
47
|
+
define_obj :network
|
48
|
+
obj_needs(:CloudObject, :network_connection)
|
49
|
+
obj_needs(:data, :network_name)
|
50
|
+
|
51
|
+
# defines setup Cloud data
|
52
|
+
# This definition is required only if you need to change the predefined data.
|
53
|
+
# To get details on what kind of parameters can be applied to a CloudData, see lib/defaults.yaml
|
54
|
+
define_data(:account_id, {:provisioned_by => :setup, :desc => 'MyCloud username'})
|
55
|
+
define_data(:account_key, {:provisioned_by => :setup, :desc => 'HPCloud secret Key'})
|
56
|
+
define_data(:auth_uri, {:provisioned_by => :setup, :desc => 'HPCloud Authentication service URL'})
|
57
|
+
define_data(:tenant, {:provisioned_by => :setup, :desc => 'HPCloud Tenant ID'})
|
58
|
+
define_data(:compute, {:provisioned_by => :setup, :desc => 'HPCloud Compute service zone (Ex: region-a.geo-1)'})
|
59
|
+
define_data(:network, {:provisioned_by => :setup, :desc => 'HPCloud Network service zone (Ex: region-a.geo-1)'})
|
60
|
+
|
61
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# encoding: UTF-8
|
3
2
|
|
4
3
|
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
@@ -15,31 +14,20 @@
|
|
15
14
|
# See the License for the specific language governing permissions and
|
16
15
|
# limitations under the License.
|
17
16
|
|
18
|
-
|
19
|
-
require 'yaml'
|
20
|
-
#require_relative 'log.rb'
|
21
|
-
#include Logging
|
17
|
+
# This file is given as an example.
|
22
18
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
19
|
+
class Mycloud # This class is automatically derived from ForjCloudBase and ForjProcess
|
20
|
+
|
21
|
+
def provider_network_new
|
22
|
+
Fog::Network.new({:provider => :mycloud}.merge(hget_cloudObjMapping()))
|
23
|
+
end
|
24
|
+
|
25
|
+
def provider_query_network(oNetwork, name)
|
26
|
+
oNetwork.networks.all(:name => name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def provider_create_network(oNetwork, name)
|
30
|
+
oNetwork.networks.create(:name => name)
|
31
|
+
end
|
35
32
|
|
36
|
-
def dump_values(string, path)
|
37
|
-
begin
|
38
|
-
File.open(path, 'w') do |out|
|
39
|
-
YAML.dump(string, out)
|
40
|
-
end
|
41
|
-
rescue => e
|
42
|
-
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
43
|
-
end
|
44
|
-
end
|
45
33
|
end
|
data/lib/log.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'rubygems'
|
22
22
|
require 'logger'
|
23
23
|
require 'ansi'
|
24
|
+
require 'ansi/logger'
|
24
25
|
|
25
26
|
require 'require_relative'
|
26
27
|
|
@@ -58,7 +59,17 @@ module Logging
|
|
58
59
|
@level = level
|
59
60
|
@oOutLogger.level = @level
|
60
61
|
@oOutLogger.formatter = proc do |severity, datetime, progname, msg|
|
61
|
-
|
62
|
+
case severity
|
63
|
+
when 'ANY'
|
64
|
+
str = "#{msg} \n"
|
65
|
+
when "ERROR", "FATAL"
|
66
|
+
str = ANSI.bold(ANSI.red("#{severity}!!!")) + ": #{msg} \n"
|
67
|
+
when "WARN"
|
68
|
+
str = ANSI.bold(ANSI.yellow("WARNING")) + ": #{msg} \n"
|
69
|
+
else
|
70
|
+
str = "#{severity}: #{msg} \n"
|
71
|
+
end
|
72
|
+
str
|
62
73
|
end
|
63
74
|
end
|
64
75
|
|
data/lib/repositories.rb
CHANGED
data/lib/ssh.rb
CHANGED
@@ -23,25 +23,28 @@ include SecurityGroup
|
|
23
23
|
# ssh module
|
24
24
|
#
|
25
25
|
module Ssh
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def connect(name, server, oConfig)
|
27
|
+
# Following line to remove as soon as ssh function is implemented with forj-lib framework
|
28
|
+
Logging.warning("This function may not work appropriately. Currenty under development. Thank you for your understanding.")
|
29
29
|
|
30
|
-
|
30
|
+
msg = 'logging into %s : %s' % [name, server]
|
31
|
+
Logging.info(msg)
|
31
32
|
|
32
|
-
|
33
|
+
oForjAccount = ForjAccount.new(oConfig)
|
33
34
|
|
34
|
-
|
35
|
+
oForjAccount.ac_load()
|
35
36
|
|
36
|
-
|
37
|
-
connection = '%s/ssh.sh %s %s %s' % [$LIB_PATH, name, server, File.join(oKey[:keypair_path],oKey[:private_key_name]) ]
|
37
|
+
oKey = SecurityGroup.keypair_detect(oForjAccount.get(:keypair_name), oForjAccount.get(:keypair_path))
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
Kernel.system(update)
|
39
|
+
update = '%s/ssh.sh -u %s' % [ $LIB_PATH, oConfig.get(:account_name)]
|
40
|
+
connection = '%s/ssh.sh %s %s %s' % [$LIB_PATH, name, server, File.join(oKey[:keypair_path],oKey[:private_key_name]) ]
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
# update the list of servers
|
43
|
+
Logging.debug("Executing '%s'" % update)
|
44
|
+
Kernel.system(update)
|
45
|
+
|
46
|
+
# connect to the server
|
47
|
+
Logging.debug("Executing '%s'" % connection)
|
48
|
+
Kernel.system(connection)
|
49
|
+
end
|
47
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- forj team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 1.3.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: json
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.7.5
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.7.5
|
139
153
|
description: forj cli - See https://www.forj.io for documentation/information
|
140
154
|
email:
|
141
155
|
- forj@forj.io
|
@@ -149,13 +163,10 @@ files:
|
|
149
163
|
- lib/connection.rb
|
150
164
|
- lib/network.rb
|
151
165
|
- lib/security.rb
|
152
|
-
- lib/yaml_parse.rb
|
153
166
|
- lib/defaults.yaml
|
154
167
|
- lib/down.rb
|
155
|
-
- lib/boot.rb
|
156
168
|
- lib/appinit.rb
|
157
169
|
- lib/forj-settings.rb
|
158
|
-
- lib/setup.rb
|
159
170
|
- lib/repositories.rb
|
160
171
|
- lib/ssh.rb
|
161
172
|
- lib/ssh.sh
|
@@ -163,6 +174,25 @@ files:
|
|
163
174
|
- lib/helpers.rb
|
164
175
|
- lib/forj-config.rb
|
165
176
|
- lib/forj-account.rb
|
177
|
+
- lib/build_tmpl/bootstrap_build.sh
|
178
|
+
- lib/build_tmpl/write-mime-multipart.py
|
179
|
+
- lib/forj/ForjCore.rb
|
180
|
+
- lib/forj/ForjCli.rb
|
181
|
+
- lib/forj/process/ForjProcess.rb
|
182
|
+
- lib/lib-forj/lib/providers/templates/compute.rb
|
183
|
+
- lib/lib-forj/lib/providers/templates/network.rb
|
184
|
+
- lib/lib-forj/lib/providers/templates/core.rb
|
185
|
+
- lib/lib-forj/lib/providers/hpcloud/security_groups.rb
|
186
|
+
- lib/lib-forj/lib/providers/hpcloud/Hpcloud.rb
|
187
|
+
- lib/lib-forj/lib/providers/hpcloud/compute.rb
|
188
|
+
- lib/lib-forj/lib/providers/hpcloud/network.rb
|
189
|
+
- lib/lib-forj/lib/core_process/global_process.rb
|
190
|
+
- lib/lib-forj/lib/core_process/CloudProcess.rb
|
191
|
+
- lib/lib-forj/lib/core_process/network_process.rb
|
192
|
+
- lib/lib-forj/lib/core/definition.rb
|
193
|
+
- lib/lib-forj/lib/core/core.rb
|
194
|
+
- lib/lib-forj/lib/core/definition_internal.rb
|
195
|
+
- lib/lib-forj/lib/lib-forj.rb
|
166
196
|
- spec/boot_spec.rb
|
167
197
|
- spec/connection_spec.rb
|
168
198
|
- spec/down_spec.rb
|
@@ -171,7 +201,6 @@ files:
|
|
171
201
|
- spec/setup_spec.rb
|
172
202
|
- spec/spec_helper.rb
|
173
203
|
- spec/ssh_spec.rb
|
174
|
-
- spec/yaml_parse_spec.rb
|
175
204
|
- spec/forj-config_spec.rb
|
176
205
|
- Rakefile
|
177
206
|
- Gemfile
|
data/lib/boot.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
|
19
|
-
require_relative 'network.rb'
|
20
|
-
include Network
|
21
|
-
require_relative 'yaml_parse.rb'
|
22
|
-
include YamlParse
|
23
|
-
require_relative 'security.rb'
|
24
|
-
include SecurityGroup
|
25
|
-
require_relative 'repositories.rb'
|
26
|
-
include Repositories
|
27
|
-
#require_relative 'log.rb'
|
28
|
-
#include Logging
|
29
|
-
require_relative 'helpers.rb'
|
30
|
-
include Helpers
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
# Boot module
|
35
|
-
#
|
36
|
-
module Boot
|
37
|
-
def boot(blueprint, name, build, boothook, box_name, oConfig)
|
38
|
-
begin
|
39
|
-
|
40
|
-
Logging.fatal(1, 'FORJ account not specified. Did you used `forj setup`, before?') if not oConfig.get(:account_name)
|
41
|
-
|
42
|
-
# Check options and set data
|
43
|
-
cloud_provider = oConfig.get(:provider_name, 'hpcloud')
|
44
|
-
|
45
|
-
if cloud_provider != 'hpcloud'
|
46
|
-
Logging.fatal(1, "forj setup support only hpcloud. '%s' is currently not supported." % cloud_provider)
|
47
|
-
end
|
48
|
-
|
49
|
-
initial_msg = "booting %s on %s\nCheck log with `tail -f ~/.forj/forj.log`.\nUse --verbose or --debug for more boot status on screen" % [blueprint , cloud_provider]
|
50
|
-
Logging.high_level_msg(initial_msg) #################
|
51
|
-
|
52
|
-
# Initialize defaults
|
53
|
-
maestro_url = oConfig.get(:maestro_url)
|
54
|
-
|
55
|
-
infra_dir = File.expand_path(oConfig.get(:infra_repo))
|
56
|
-
|
57
|
-
# Ask information if needed.
|
58
|
-
if not Dir.exist?(File.expand_path(infra_dir))
|
59
|
-
Logging.warning(<<-END
|
60
|
-
Your infra workspace directory is missing.
|
61
|
-
|
62
|
-
Forj uses an infra workspace directory to store any kind of data that are private to you.
|
63
|
-
We provides ways to send those data securily to your new Forge instance, as metadata.
|
64
|
-
In production case, we suggest you to keep it safe in your SCM preferred database.
|
65
|
-
|
66
|
-
If you already have an existing infra workspace, use 'forj set infra_repo=<PathToYourRepo>' to set it and restart.
|
67
|
-
|
68
|
-
Otherwise, we will build a new one with some predefined data, you can review and update later.
|
69
|
-
END
|
70
|
-
)
|
71
|
-
sAsk = "Do you want to create a new one from Maestro (yes/no)?" % [infra_dir]
|
72
|
-
bBuildInfra=agree(sAsk)
|
73
|
-
if not bBuildInfra
|
74
|
-
puts 'Process aborted on your demand.'
|
75
|
-
exit 0
|
76
|
-
end
|
77
|
-
else
|
78
|
-
# Check about infra repo compatibility with forj cli
|
79
|
-
bBuildInfra = Repositories.infra_rebuild_required?(oConfig, infra_dir)
|
80
|
-
end
|
81
|
-
|
82
|
-
# Get FORJ DNS setting
|
83
|
-
yDNS = rhGet(oConfig.hAccountData, :dns)
|
84
|
-
Logging.fatal(1, "DNS or domain name are missing. Please execute forj setup %s" % oConfig.getAccountData(:account, 'name')) if not yDNS
|
85
|
-
|
86
|
-
branch = oConfig.get(:branch, 'master')
|
87
|
-
|
88
|
-
# Step Maestro Clone
|
89
|
-
if not oConfig.get(:maestro_repo)
|
90
|
-
Logging.state("cloning maestro repo from '%s' - branch '%s'" % [maestro_url, branch])
|
91
|
-
Repositories.clone_repo(maestro_url, oConfig)
|
92
|
-
maestro_repo=File.expand_path('~/.forj/maestro')
|
93
|
-
else
|
94
|
-
maestro_repo=File.expand_path(oConfig.get(:maestro_repo))
|
95
|
-
if not File.exists?('%s/templates/infra/maestro.box.master.env' % [maestro_repo])
|
96
|
-
msg = <<-END
|
97
|
-
'#{maestro_repo}' is not a recognized Maestro repository or is too old. forj cli searched for templates/infra/maestro.box.master.env
|
98
|
-
|
99
|
-
Suggestion:
|
100
|
-
1. Clone #{maestro_url} to a different location.
|
101
|
-
$ mkdir -p ~/src/forj-oss
|
102
|
-
$ cd ~/src/forj-oss
|
103
|
-
$ git clone #{maestro_url}
|
104
|
-
2. Use this master branch of maestro repository with forj
|
105
|
-
$ forj set maestro_repo=~/src/forj-oss/maestro
|
106
|
-
|
107
|
-
then retry your boot.
|
108
|
-
END
|
109
|
-
Logging.fatal(1, msg)
|
110
|
-
end
|
111
|
-
Logging.info("Using your maestro cloned repo '%s'" % maestro_repo)
|
112
|
-
end
|
113
|
-
|
114
|
-
bBuildInfra = Repositories.infra_rebuild(oConfig, infra_dir) unless bBuildInfra
|
115
|
-
|
116
|
-
if bBuildInfra
|
117
|
-
Logging.info("Building your infra... in '%s'" % [infra_dir])
|
118
|
-
Repositories.create_infra(maestro_repo, branch)
|
119
|
-
else
|
120
|
-
Logging.info("Re-using your infra... in '%s'" % [infra_dir]) if not bBuildInfra
|
121
|
-
end
|
122
|
-
|
123
|
-
Repositories.ensure_build_env_file(maestro_url, maestro_repo, branch)
|
124
|
-
|
125
|
-
# Connect to services
|
126
|
-
oFC=ForjConnection.new(oConfig)
|
127
|
-
|
128
|
-
Logging.info('Configuring network \'%s\'' % [oConfig.get('network_name')])
|
129
|
-
begin
|
130
|
-
network = Network.get_or_create_network(oFC, oConfig.get('network_name'))
|
131
|
-
subnet = Network.get_or_create_subnet(oFC, network.id, network.name)
|
132
|
-
Network.get_or_create_router(oFC, network, subnet)
|
133
|
-
rescue => e
|
134
|
-
Logging.fatal(1, "Network properly configured is required.", e)
|
135
|
-
end
|
136
|
-
|
137
|
-
Logging.info('Configuring keypair \'%s\'' % [oConfig.get('keypair_name')])
|
138
|
-
SecurityGroup.hpc_import_key(oConfig)
|
139
|
-
|
140
|
-
|
141
|
-
Logging.info('Configuring Security Group \'%s\'' % [oConfig.get('security_group')])
|
142
|
-
security_group = SecurityGroup.get_or_create_security_group(oFC, oConfig.get('security_group'))
|
143
|
-
ports = oConfig.get(:ports)
|
144
|
-
|
145
|
-
ports.each do |port|
|
146
|
-
port = port.to_s if port.class != String
|
147
|
-
if not (/^\d+(-\d+)?$/ =~ port)
|
148
|
-
Logging.error("Port '%s' is not valid. Must be <Port> or <PortMin>-<PortMax>" % [port])
|
149
|
-
else
|
150
|
-
mPortFound = /^(\d+)(-(\d+))?$/.match(port)
|
151
|
-
portmin = mPortFound[1]
|
152
|
-
portmax = (mPortFound[3]) ? (mPortFound[3]) : (portmin)
|
153
|
-
Network.get_or_create_rule(oFC, security_group.id, 'tcp', portmin, portmax)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
oBuildEnv = BuildEnv.new(oConfig)
|
160
|
-
ENV['FORJ_CLI_ENV'] = oBuildEnv.sBuildEnvFile
|
161
|
-
oBuildEnv.set('FORJ_HPC', oFC.sAccountName)
|
162
|
-
oBuildEnv.set('FORJ_HPC_NET', network.name)
|
163
|
-
oBuildEnv.set('FORJ_SECURITY_GROUP', oConfig.get('security_group'))
|
164
|
-
oBuildEnv.set('FORJ_KEYPAIR', oConfig.get('keypair_name'))
|
165
|
-
oBuildEnv.set('FORJ_HPC_NOVA_KEYPUB', oConfig.get('keypair_path') + '.pub')
|
166
|
-
oBuildEnv.set('FORJ_BASE_IMG', oConfig.get('image_name'))
|
167
|
-
oBuildEnv.set('FORJ_FLAVOR', oConfig.get('flavor_name'))
|
168
|
-
oBuildEnv.set('FORJ_BP_FLAVOR', oConfig.get('bp_flavor'))
|
169
|
-
oBuildEnv.set('FORJ_TENANT_NAME', oConfig.get(:tenant_name))
|
170
|
-
oBuildEnv.set('FORJ_HPC_COMPUTE', rhGet(oConfig.oConfig.ExtraGet(:hpc_accounts, oFC.sAccountName, :regions), :compute))
|
171
|
-
|
172
|
-
|
173
|
-
oBuildEnv.set('FORJ_DOMAIN', yDNS[:domain_name])
|
174
|
-
|
175
|
-
if yDNS[:tenant_id]
|
176
|
-
oBuildEnv.set('FORJ_DNS_TENANTID', yDNS[:tenant_id])
|
177
|
-
oBuildEnv.set('FORJ_DNS_ZONE', yDNS[:service])
|
178
|
-
end
|
179
|
-
oBuildEnv.save()
|
180
|
-
|
181
|
-
# run build.sh to boot maestro
|
182
|
-
puts
|
183
|
-
|
184
|
-
build = 'bin/build.sh' unless build
|
185
|
-
|
186
|
-
build_config = oConfig.get('build_config')
|
187
|
-
box_name = oConfig.get('box_name')
|
188
|
-
|
189
|
-
arg = '--meta blueprint=%s ' % [blueprint]
|
190
|
-
arg += "--test-box '%s' " % oConfig.get(:test_box) if oConfig.exist?(:test_box)
|
191
|
-
|
192
|
-
command = '%s --build_ID %s --box-name %s --build-conf-dir %s --build-config %s --gitBranch %s --debug-box %s' % [build, name, box_name, infra_dir, build_config, branch, arg]
|
193
|
-
|
194
|
-
maestro_build_path = File.join(maestro_repo, 'build')
|
195
|
-
|
196
|
-
current_dir = Dir.pwd
|
197
|
-
Dir.chdir(maestro_build_path)
|
198
|
-
|
199
|
-
Logging.info("Calling '%s' from '%s'" % [build, Dir.pwd])
|
200
|
-
Logging.debug("%s=%s %s" % ['FORJ_CLI_ENV', ENV['FORJ_CLI_ENV'], command])
|
201
|
-
Kernel.system(ENV, command)
|
202
|
-
Dir.chdir(current_dir)
|
203
|
-
|
204
|
-
# if test
|
205
|
-
# Logging.debug 'test flag is on, deleting objects'
|
206
|
-
# Network.delete_router_interface(subnet.id, router)
|
207
|
-
# Network.delete_subnet(subnet.id)
|
208
|
-
# Network.delete_network(network.name)
|
209
|
-
# end
|
210
|
-
|
211
|
-
rescue Interrupt
|
212
|
-
Logging.message("\n'%s' boot from '%s' interrupted by user" % [name, blueprint])
|
213
|
-
rescue => e
|
214
|
-
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
|
221
|
-
class BuildEnv
|
222
|
-
|
223
|
-
attr_reader :sBuildEnvFile
|
224
|
-
|
225
|
-
def initialize(oConfig)
|
226
|
-
|
227
|
-
oConfig.oConfig.fatal_if_inexistent(:infra_repo)
|
228
|
-
oConfig.oConfig.fatal_if_inexistent(:account_name)
|
229
|
-
|
230
|
-
sBuildDir = File.expand_path(File.join(oConfig.get(:infra_repo),'build'))
|
231
|
-
@sBuildEnvFile = File.join(sBuildDir, oConfig.get(:account_name)+'.build.env')
|
232
|
-
AppInit.ensure_dir_exists(sBuildDir)
|
233
|
-
@yBuildEnvVar = {}
|
234
|
-
@oConfig = oConfig
|
235
|
-
end
|
236
|
-
|
237
|
-
def set(key, value)
|
238
|
-
# This file creates the in-memory data required to configure specific project build_env.
|
239
|
-
# Name : ~/.forj/account/<Account>.build.env
|
240
|
-
if value
|
241
|
-
Logging.debug("Setting '%s' = '%s'" % [key, value])
|
242
|
-
@yBuildEnvVar[key] = value
|
243
|
-
else
|
244
|
-
Logging.debug("'%s' is not set" % [key])
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
def save()
|
249
|
-
begin
|
250
|
-
File.open(@sBuildEnvFile, 'w') do |out|
|
251
|
-
@yBuildEnvVar.each do | key, value |
|
252
|
-
desc = @oConfig.oConfig.getAppDefault(:description, key)
|
253
|
-
out.write("# %s - %s\n" % [key, desc]) if desc
|
254
|
-
value = "" if not value
|
255
|
-
out.write("%s='%s'\n\n" % [key, value])
|
256
|
-
end
|
257
|
-
end
|
258
|
-
Logging.debug("'%s' written." % [@sBuildEnvFile])
|
259
|
-
rescue => e
|
260
|
-
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
data/lib/setup.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
require 'rubygems'
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
# Setup module call the hpcloud functions
|
23
|
-
#
|
24
|
-
module Setup
|
25
|
-
def setup(oConfig)
|
26
|
-
|
27
|
-
# TODO: Provide a way to re-edit all or partially elements set up by this function.
|
28
|
-
begin
|
29
|
-
oForjAccount = ForjAccount.new(oConfig)
|
30
|
-
|
31
|
-
oForjAccount.ac_load()
|
32
|
-
# TODO: Provide a way to update partially some account data.
|
33
|
-
oForjAccount.setup() # any kind of setup, ask from users.
|
34
|
-
|
35
|
-
oForjAccount.set(:flavor_name, 'standard.medium') if oForjAccount.exist?(:flavor_name) != oForjAccount.sAccountName
|
36
|
-
oForjAccount.set(:bp_flavor, 'standard.small') if oForjAccount.exist?(:bp_flavor) != oForjAccount.sAccountName
|
37
|
-
oForjAccount.ac_save()
|
38
|
-
|
39
|
-
rescue RuntimeError => e
|
40
|
-
Logging.fatal(1,e.message)
|
41
|
-
rescue => e
|
42
|
-
Logging.fatal(1,"Unable to run setup" , e)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|