forj 0.0.18 → 0.0.19
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/bin/forj +6 -0
- data/lib/boot.rb +59 -48
- data/lib/catalog.yaml +1 -1
- data/lib/connection.rb +10 -10
- data/lib/network.rb +8 -6
- data/lib/security.rb +8 -16
- data/lib/setup.rb +2 -86
- data/lib/ssh.rb +15 -0
- data/lib/yaml_parse.rb +1 -1
- metadata +12 -11
data/bin/forj
CHANGED
|
@@ -63,6 +63,7 @@ class Forj < Thor
|
|
|
63
63
|
desc 'boot', 'boot a Maestro box and instruct it to provision the blueprint'
|
|
64
64
|
method_option :build_conf_dir, :aliases => '-c', :desc => 'build config dir to use'
|
|
65
65
|
method_option :branch, :aliases => '-b', :desc => 'branch to use'
|
|
66
|
+
method_option :test_box, :aliases => '-t', :desc => 'test box'
|
|
66
67
|
def boot(blueprint, on, cloud_provider, as, name, test=false)
|
|
67
68
|
build_conf_dir = options[:build_conf_dir]
|
|
68
69
|
branch = options[:branch]
|
|
@@ -82,6 +83,11 @@ class Forj < Thor
|
|
|
82
83
|
Down.down(name)
|
|
83
84
|
end
|
|
84
85
|
|
|
86
|
+
desc 'ssh', ''
|
|
87
|
+
def ssh
|
|
88
|
+
puts 'ssh'
|
|
89
|
+
end
|
|
90
|
+
|
|
85
91
|
desc 'setup', 'set the credentials for forj cli'
|
|
86
92
|
def setup
|
|
87
93
|
Setup.setup
|
data/lib/boot.rb
CHANGED
|
@@ -30,55 +30,66 @@ include Repositories
|
|
|
30
30
|
|
|
31
31
|
module Boot
|
|
32
32
|
def boot(blueprint, cloud_provider, name, build_config_dir, branch, test=false)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
begin
|
|
34
|
+
|
|
35
|
+
puts 'booting %s on %s' % [blueprint, cloud_provider]
|
|
36
|
+
|
|
37
|
+
# get definitions from yaml
|
|
38
|
+
forj_dir = File.expand_path(File.dirname(__FILE__))
|
|
39
|
+
Dir.chdir(forj_dir)
|
|
40
|
+
definitions = YamlParse.get_values('../lib/catalog.yaml')
|
|
41
|
+
|
|
42
|
+
# clone the maestro repo
|
|
43
|
+
Repositories.clone_repo
|
|
44
|
+
|
|
45
|
+
# create the network where maestro will land
|
|
46
|
+
network = Network.create_network(name)
|
|
47
|
+
subnet = Network.create_subnet(network.id, name)
|
|
48
|
+
router = Network.get_router(definitions[blueprint]['router'])
|
|
49
|
+
Network.create_router_interface(subnet.id, router)
|
|
50
|
+
|
|
51
|
+
# create the security groups for the blueprint
|
|
52
|
+
security_group = SecurityGroup.create_security_group(blueprint)
|
|
53
|
+
|
|
54
|
+
ports = definitions['redstone']['ports']
|
|
55
|
+
|
|
56
|
+
ports.each do|port|
|
|
57
|
+
Network.create_security_group_rule(security_group.id, 'tcp', port, port)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
ENV['FORJ_HPC_NETID'] = network.id
|
|
61
|
+
ENV['FORJ_SECURITY_GROUP'] = security_group.name
|
|
62
|
+
ENV['FORJ_KEYPAIR'] = definitions[blueprint]['keypair']
|
|
63
|
+
ENV['FORJ_HPC_NOVA_KEYPUB'] = definitions[blueprint]['keypair']
|
|
64
|
+
|
|
65
|
+
# run build.sh to boot maestro
|
|
66
|
+
current_dir = Dir.pwd
|
|
67
|
+
home = File.expand_path('~')
|
|
68
|
+
build_path = home + '/.hpcloud/maestro/build'
|
|
69
|
+
Dir.chdir(build_path)
|
|
70
|
+
|
|
71
|
+
if build_config_dir != nil
|
|
72
|
+
command = 'bin/build.sh --build_ID maestro.%s --box-name maestro --build-conf-dir %s --build-config box-13.5 --gitBranch %s' % [name, build_config_dir, branch]
|
|
73
|
+
else
|
|
74
|
+
command = 'bin/build.sh --build_ID %s --box-name maestro --build-conf-dir ~/.hpcloud/maestro/build/conf --build-config box' % [name]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
Kernel.system(command)
|
|
78
|
+
Dir.chdir(current_dir)
|
|
79
|
+
|
|
80
|
+
if test
|
|
81
|
+
puts 'test flag is on, deleting objects'
|
|
82
|
+
Network.delete_router_interface(subnet.id, router)
|
|
83
|
+
Network.delete_subnet(subnet.id)
|
|
84
|
+
Network.delete_network(network.name)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
rescue SystemExit, Interrupt
|
|
88
|
+
puts 'process interrupted by user'
|
|
89
|
+
rescue Exception => e
|
|
90
|
+
puts e
|
|
58
91
|
end
|
|
59
92
|
|
|
60
|
-
# run build.sh to boot maestro
|
|
61
|
-
current_dir = Dir.pwd
|
|
62
|
-
home = File.expand_path('~')
|
|
63
|
-
build_path = home + '/.hpcloud/maestro/build'
|
|
64
|
-
Dir.chdir(build_path)
|
|
65
|
-
|
|
66
|
-
if build_config_dir != nil
|
|
67
|
-
command = './bin/build.sh --build_ID maestro.10 --box-name maestro --build-conf-dir %s --build-config box --setBranch %s' % [build_config_dir, branch]
|
|
68
|
-
else
|
|
69
|
-
command = './bin/build.sh --build_ID maestro.10 --box-name maestro --build-config box'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Kernel.system(command)
|
|
74
|
-
Dir.chdir(current_dir)
|
|
75
|
-
|
|
76
|
-
if test
|
|
77
|
-
puts 'test flag is on, deleting objects'
|
|
78
|
-
Network.delete_router_interface(subnet.id, router)
|
|
79
|
-
Network.delete_subnet(subnet.id)
|
|
80
|
-
Network.delete_network(network.name)
|
|
81
|
-
#Network.delete_security_group(security_group.id)
|
|
82
|
-
end
|
|
83
93
|
end
|
|
94
|
+
|
|
84
95
|
end
|
data/lib/catalog.yaml
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
redstone:
|
|
16
16
|
image: proto2b
|
|
17
17
|
flavor: standard.xsmall
|
|
18
|
-
ports: [22, 80, 8080,
|
|
18
|
+
ports: [22, 80, 443, 3131, 3000, 3132, 3133, 3134, 3135, 4505, 4506, 5000, 5666, 8000, 8080, 8081, 8083, 8125, 8139, 8140, 8773, 8774, 8776, 9292, 29418, 35357]
|
|
19
19
|
keypair: nova
|
|
20
20
|
router: private-ext
|
|
21
21
|
|
data/lib/connection.rb
CHANGED
|
@@ -24,7 +24,7 @@ module Connection
|
|
|
24
24
|
|
|
25
25
|
def compute
|
|
26
26
|
credentials = get_credentials
|
|
27
|
-
|
|
27
|
+
Fog::Compute.new({
|
|
28
28
|
:provider => 'HP',
|
|
29
29
|
:hp_access_key => credentials['access_key'],
|
|
30
30
|
:hp_secret_key => credentials['secret_key'],
|
|
@@ -37,7 +37,7 @@ module Connection
|
|
|
37
37
|
|
|
38
38
|
def network
|
|
39
39
|
credentials = get_credentials
|
|
40
|
-
|
|
40
|
+
Fog::HP::Network.new({
|
|
41
41
|
:hp_access_key => credentials['access_key'],
|
|
42
42
|
:hp_secret_key => credentials['secret_key'],
|
|
43
43
|
:hp_auth_uri => credentials['auth_uri'],
|
|
@@ -50,18 +50,18 @@ end
|
|
|
50
50
|
|
|
51
51
|
def get_credentials
|
|
52
52
|
home = File.expand_path('~')
|
|
53
|
-
|
|
54
|
-
template = YAML.load_file(
|
|
53
|
+
creds = '%s/.hpcloud/accounts/hp' % [home]
|
|
54
|
+
template = YAML.load_file(creds)
|
|
55
55
|
credentials = Hash.new
|
|
56
56
|
|
|
57
57
|
begin
|
|
58
|
-
credentials['access_key'] = template[
|
|
59
|
-
credentials['secret_key'] = template[
|
|
60
|
-
credentials['auth_uri'] = template[
|
|
61
|
-
credentials['tenant_id'] = template[
|
|
62
|
-
credentials['availability_zone'] = template[
|
|
58
|
+
credentials['access_key'] = template[:credentials][:account_id]
|
|
59
|
+
credentials['secret_key'] = template[:credentials][:secret_key]
|
|
60
|
+
credentials['auth_uri'] = template[:credentials][:auth_uri]
|
|
61
|
+
credentials['tenant_id'] = template[:credentials][:tenant_id]
|
|
62
|
+
credentials['availability_zone'] = template[:regions][:monitoring]
|
|
63
63
|
rescue
|
|
64
|
-
puts 'your credentials are not configured, delete the file %s and run forj setup again' % [
|
|
64
|
+
puts 'your credentials are not configured, delete the file %s and run forj setup again' % [creds]
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
credentials
|
data/lib/network.rb
CHANGED
|
@@ -22,7 +22,7 @@ include Connection
|
|
|
22
22
|
module Network
|
|
23
23
|
|
|
24
24
|
def create_network(name)
|
|
25
|
-
|
|
25
|
+
Connection.network.networks.create(:name => name)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def delete_network(network_name)
|
|
@@ -31,7 +31,7 @@ module Network
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def create_subnet(network_id, name)
|
|
34
|
-
|
|
34
|
+
Connection.network.subnets.create(
|
|
35
35
|
:network_id => network_id,
|
|
36
36
|
:name => name,
|
|
37
37
|
:cidr => get_next_subnet,
|
|
@@ -44,20 +44,22 @@ module Network
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def get_subnet(name)
|
|
47
|
-
|
|
47
|
+
Connection.network.subnets.all(:name => name)[0]
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def get_router(name)
|
|
51
51
|
routers = Connection.network.routers.all({:name => name})
|
|
52
52
|
router = nil
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
routers.each do|r|
|
|
54
55
|
router = r
|
|
55
56
|
end
|
|
57
|
+
|
|
56
58
|
router
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
def create_router_interface(subnet_id, router)
|
|
60
|
-
|
|
62
|
+
router.add_interface(subnet_id, nil)
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
def delete_router_interface(subnet_id, router)
|
|
@@ -65,7 +67,7 @@ module Network
|
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
def create_router(name)
|
|
68
|
-
|
|
70
|
+
Connection.network.routers.create(
|
|
69
71
|
:name => name,
|
|
70
72
|
:admin_state_up => true
|
|
71
73
|
)
|
data/lib/security.rb
CHANGED
|
@@ -24,19 +24,11 @@ include Connection
|
|
|
24
24
|
module SecurityGroup
|
|
25
25
|
|
|
26
26
|
def create_security_group(name)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else
|
|
33
|
-
description = 'Security group for blueprint %s' % [name]
|
|
34
|
-
security_group = Connection.network.security_groups.create(
|
|
35
|
-
:name => name,
|
|
36
|
-
:description => description
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
security_group
|
|
27
|
+
description = 'Security group for blueprint %s' % [name]
|
|
28
|
+
Connection.network.security_groups.create(
|
|
29
|
+
:name => name,
|
|
30
|
+
:description => description
|
|
31
|
+
)
|
|
40
32
|
end
|
|
41
33
|
|
|
42
34
|
def delete_security_group(security_group_id)
|
|
@@ -45,7 +37,7 @@ module SecurityGroup
|
|
|
45
37
|
|
|
46
38
|
def create_security_group_rule(security_group_id, protocol, port_min, port_max)
|
|
47
39
|
begin
|
|
48
|
-
|
|
40
|
+
Connection.network.security_group_rules.create(
|
|
49
41
|
:security_group_id => security_group_id,
|
|
50
42
|
:direction => 'ingress',
|
|
51
43
|
:protocol => protocol,
|
|
@@ -53,7 +45,7 @@ module SecurityGroup
|
|
|
53
45
|
:port_range_max => port_max,
|
|
54
46
|
:remote_ip_prefix => '0.0.0.0/0'
|
|
55
47
|
)
|
|
56
|
-
rescue StandardError
|
|
48
|
+
rescue StandardError
|
|
57
49
|
puts 'error creating the rule for port %s' % [port_min]
|
|
58
50
|
end
|
|
59
51
|
|
|
@@ -70,7 +62,7 @@ module SecurityGroup
|
|
|
70
62
|
# this will create a new keypair
|
|
71
63
|
key_pair = Connection.compute.key_pairs.create(:name => name)
|
|
72
64
|
key_pair.write(path)
|
|
73
|
-
rescue StandardError
|
|
65
|
+
rescue StandardError
|
|
74
66
|
puts 'error uploading the keypair'
|
|
75
67
|
end
|
|
76
68
|
end
|
data/lib/setup.rb
CHANGED
|
@@ -16,91 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
module Setup
|
|
18
18
|
def setup
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
file = get_credentials_file
|
|
23
|
-
template = YAML.load_file(file)
|
|
24
|
-
|
|
25
|
-
# access key
|
|
26
|
-
begin
|
|
27
|
-
access_key = template['default']['access_key']
|
|
28
|
-
rescue
|
|
29
|
-
puts 'which access key to use'
|
|
30
|
-
access_key = $stdin.gets.chomp
|
|
31
|
-
save_to_credentials_file('access_key', access_key)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# secret key
|
|
35
|
-
begin
|
|
36
|
-
secret_key = template['default']['secret_key']
|
|
37
|
-
rescue
|
|
38
|
-
puts 'which secret_key key to use'
|
|
39
|
-
secret_key = $stdin.gets.chomp
|
|
40
|
-
save_to_credentials_file('secret_key', secret_key)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# auth uri
|
|
44
|
-
begin
|
|
45
|
-
auth_uri = template['default']['auth_uri']
|
|
46
|
-
rescue
|
|
47
|
-
puts 'which auth url to use'
|
|
48
|
-
auth_uri = $stdin.gets.chomp
|
|
49
|
-
save_to_credentials_file('auth_uri', auth_uri)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# tenant id
|
|
53
|
-
begin
|
|
54
|
-
tenant_id = template['default']['tenant_id']
|
|
55
|
-
rescue
|
|
56
|
-
puts 'which tenant id to use'
|
|
57
|
-
tenant_id = $stdin.gets.chomp
|
|
58
|
-
save_to_credentials_file('tenant_id', tenant_id)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# availability zone
|
|
62
|
-
begin
|
|
63
|
-
availability_zone = template['default']['availability_zone']
|
|
64
|
-
rescue
|
|
65
|
-
puts 'which availability zone to use'
|
|
66
|
-
availability_zone = $stdin.gets.chomp
|
|
67
|
-
save_to_credentials_file('availability_zone', availability_zone)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def create_credentials_file
|
|
74
|
-
home = File.expand_path('~')
|
|
75
|
-
file = home + '/.hpcloud/.hpcloud'
|
|
76
|
-
|
|
77
|
-
unless File.file?(file)
|
|
78
|
-
File.open(file, 'w') do |f|
|
|
79
|
-
f.write('default:' + "\n")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def create_dir
|
|
86
|
-
home = File.expand_path('~')
|
|
87
|
-
path = home + '/.hpcloud'
|
|
88
|
-
unless File.directory?(path) do
|
|
89
|
-
Dir.mkdir(path)
|
|
90
|
-
end
|
|
19
|
+
Kernel.system('hpcloud account:setup')
|
|
20
|
+
Kernel.system('hpcloud keypairs:add nova')
|
|
91
21
|
end
|
|
92
22
|
end
|
|
93
|
-
|
|
94
|
-
def get_credentials_file
|
|
95
|
-
home = File.expand_path('~')
|
|
96
|
-
file = home + '/.hpcloud/.hpcloud'
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def save_to_credentials_file(key, value)
|
|
100
|
-
home = File.expand_path('~')
|
|
101
|
-
file = home + '/.hpcloud/.hpcloud'
|
|
102
|
-
|
|
103
|
-
File.open(file, 'a') do |f|
|
|
104
|
-
f.write(' ' + key + ': ' + value + "\n")
|
|
105
|
-
end
|
|
106
|
-
end
|
data/lib/ssh.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
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.
|
data/lib/yaml_parse.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forj
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.19
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -13,7 +13,7 @@ date: 2014-06-12 00:00:00.000000000 Z
|
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: thor
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &18152220 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: 0.16.0
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *18152220
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: fog
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &18149360 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: 1.22.1
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *18149360
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: hpcloud
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &18147220 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: 2.0.6
|
|
44
44
|
type: :runtime
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *18147220
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: git
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &18145480 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,10 +54,10 @@ dependencies:
|
|
|
54
54
|
version: 1.2.7
|
|
55
55
|
type: :runtime
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *18145480
|
|
58
58
|
- !ruby/object:Gem::Dependency
|
|
59
59
|
name: rbx-require-relative
|
|
60
|
-
requirement: &
|
|
60
|
+
requirement: &18144380 !ruby/object:Gem::Requirement
|
|
61
61
|
none: false
|
|
62
62
|
requirements:
|
|
63
63
|
- - ! '>='
|
|
@@ -65,7 +65,7 @@ dependencies:
|
|
|
65
65
|
version: 0.0.9
|
|
66
66
|
type: :runtime
|
|
67
67
|
prerelease: false
|
|
68
|
-
version_requirements: *
|
|
68
|
+
version_requirements: *18144380
|
|
69
69
|
description: forj command line
|
|
70
70
|
email:
|
|
71
71
|
- forj@forj.io
|
|
@@ -85,6 +85,7 @@ files:
|
|
|
85
85
|
- lib/boot.rb
|
|
86
86
|
- lib/setup.rb
|
|
87
87
|
- lib/repositories.rb
|
|
88
|
+
- lib/ssh.rb
|
|
88
89
|
homepage: https://forj.io
|
|
89
90
|
licenses:
|
|
90
91
|
- Apache License, Version 2.0.
|