forj 0.0.1 → 0.0.3

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 CHANGED
@@ -61,7 +61,13 @@ class Forj < Thor
61
61
 
62
62
  desc 'boot', 'boot a Maestro box and instruct it to provision the blueprint'
63
63
  def boot(blueprint, on, cloud_provider, as, name, test=false)
64
+ current_dir = Dir.pwd
65
+ home = File.expand_path('~')
66
+ Dir.chdir(home)
67
+
64
68
  Boot.boot(blueprint, cloud_provider,name , test)
69
+
70
+ Dir.chdir(current_dir)
65
71
  end
66
72
 
67
73
  desc 'down', 'delete the Maestro box and all systems installed by the blueprint'
data/lib/boot.rb ADDED
@@ -0,0 +1,80 @@
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.
16
+
17
+ require_relative 'compute.rb'
18
+ include Compute
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
+
28
+
29
+ module Boot
30
+ def boot(blueprint, cloud_provider, name, test=false)
31
+ puts 'booting %s on %s' % [blueprint, cloud_provider]
32
+ # boot maestro
33
+
34
+ # get definitions from yaml
35
+ definitions = YamlParse.get_values('../lib/catalog.yaml')
36
+
37
+ # clone the maestro repo
38
+ Repositories.clone_repo
39
+
40
+ # upload the keypair
41
+ SecurityGroup.upload_keypair(definitions[blueprint]['keypair'])
42
+
43
+ # create the network where maestro will land
44
+ network = Network.create_network(name)
45
+ subnet = Network.create_subnet(network.id, name)
46
+ router = Network.get_router(definitions[blueprint]['router'])
47
+ Network.create_router_interface(subnet.id, router)
48
+
49
+ # create the security groups for the blueprint
50
+ security_group = SecurityGroup.create_security_group(blueprint)
51
+
52
+ for port in definitions[blueprint]['ports'] do
53
+ Network.create_security_group_rule(security_group.id, 'tcp', port, port)
54
+ end
55
+
56
+ # get image and flavor
57
+ image = Compute.get_image(definitions[blueprint]['image'])
58
+ flavor = Compute.get_flavor(definitions[blueprint]['flavor'])
59
+
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
+ command = './bin/build.sh '
67
+ options = '--box-name ' + name
68
+
69
+ Kernel.system(command + ' ' + options)
70
+ Dir.chdir(current_dir)
71
+
72
+ if test
73
+ puts 'test flag is on, deleting objects'
74
+ Network.delete_router_interface(subnet.id, router)
75
+ Network.delete_subnet(subnet.id)
76
+ Network.delete_network(network.name)
77
+ #Network.delete_security_group(security_group.id)
78
+ end
79
+ end
80
+ end
data/lib/catalog.yaml ADDED
@@ -0,0 +1,28 @@
1
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ redstone:
16
+ image: proto2b
17
+ flavor: standard.xsmall
18
+ ports: [22, 80, 8080, 8000]
19
+ keypair: nova
20
+ router: private-ext
21
+
22
+ modus:
23
+ ports: []
24
+ keypair: nova
25
+ router: private-ext
26
+
27
+ default:
28
+ maestro: https://github.com/forj-oss/maestro.git
data/lib/connection.rb CHANGED
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  def get_credentials
51
51
  home = File.expand_path('~')
52
- file = home + '/.hpcloud'
52
+ file = home + '/.hpcloud/.hpcloud'
53
53
  template = YAML.load_file(file)
54
54
  credentials = Hash.new
55
55
 
data/lib/down.rb ADDED
@@ -0,0 +1,51 @@
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.
16
+
17
+ require_relative 'compute.rb'
18
+ include Compute
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
+
26
+ module Down
27
+ def down(name)
28
+ puts 'deleting %s...' % [name]
29
+
30
+ definitions = YamlParse.get_values('../lib/catalog.yaml')
31
+
32
+ # first step is to delete the instance
33
+ Compute.delete_instance(name)
34
+
35
+ # get the subnet
36
+ subnet = Network.get_subnet(name)
37
+
38
+ # delete the router interface
39
+ router = Network.get_router(definitions['redstone']['router'])
40
+ Network.delete_router_interface(subnet.id, router)
41
+
42
+ # delete subnet
43
+ Network.delete_subnet(subnet.id)
44
+
45
+ # delete security group
46
+ # Network.delete_security_group(security_group.id)
47
+
48
+ # delete network
49
+ Network.delete_network(name)
50
+ end
51
+ end
@@ -0,0 +1,36 @@
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.
16
+
17
+ require 'git'
18
+
19
+ require_relative 'yaml_parse.rb'
20
+ include YamlParse
21
+
22
+ module Repositories
23
+ def clone_repo
24
+
25
+ definitions = YamlParse.get_values('../lib/catalog.yaml')
26
+ maestro_url = definitions['default']['maestro']
27
+
28
+ home = File.expand_path('~')
29
+ path = home + '/.hpcloud/'
30
+
31
+ unless File.directory?(path) do
32
+ g = Git.clone(maestro_url, 'maestro', :path => path)
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/security.rb CHANGED
@@ -42,27 +42,35 @@ module SecurityGroup
42
42
  end
43
43
 
44
44
  def create_security_group_rule(security_group_id, protocol, port_min, port_max)
45
- rule = Connection.network.security_group_rules.create(
46
- :security_group_id => security_group_id,
47
- :direction => 'ingress',
48
- :protocol => protocol,
49
- :port_range_min => port_min,
50
- :port_range_max => port_max,
51
- :remote_ip_prefix => '0.0.0.0/0'
52
- )
45
+ begin
46
+ rule = Connection.network.security_group_rules.create(
47
+ :security_group_id => security_group_id,
48
+ :direction => 'ingress',
49
+ :protocol => protocol,
50
+ :port_range_min => port_min,
51
+ :port_range_max => port_max,
52
+ :remote_ip_prefix => '0.0.0.0/0'
53
+ )
54
+ rescue StandardError => e
55
+ puts 'error creating the rule for port %s' % [port_min]
56
+ end
57
+
53
58
  end
54
59
 
55
60
  def delete_security_group_rule(rule_id)
56
61
  Connection.network.security_group_rules.get(rule_id).destroy
57
62
  end
58
63
 
59
- def get_keypair(name)
60
- puts 'add the path to the public key'
61
- path_to_key = $stdin.gets.chomp
62
- key_pair = Connection.compute.key_pairs.create(
63
- :name => name,
64
- :public_key => path_to_key
65
- )
64
+ def upload_keypair(name)
65
+ begin
66
+ home = File.expand_path('~')
67
+ path = home + '/.hpcloud/' + name
68
+ # this will create a new keypair
69
+ key_pair = Connection.compute.key_pairs.create(:name => name)
70
+ key_pair.write(path)
71
+ rescue StandardError => e
72
+ puts 'error uploading the keypair'
73
+ end
66
74
  end
67
75
 
68
76
  end
data/lib/setup.rb ADDED
@@ -0,0 +1,106 @@
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.
16
+
17
+ module Setup
18
+ def setup
19
+ create_dir
20
+ create_credentials_file
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
91
+ end
92
+ 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/version.rb ADDED
@@ -0,0 +1,21 @@
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.
16
+
17
+ module Version
18
+ def version
19
+ puts 'forj cli v0.1'
20
+ end
21
+ end
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.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,29 +13,27 @@ date: 2014-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &9313720 !ruby/object:Gem::Requirement
16
+ requirement: &15157140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.22.1
21
+ version: 0.19.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9313720
24
+ version_requirements: *15157140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &9313140 !ruby/object:Gem::Requirement
27
+ requirement: &15156540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '1.19'
32
+ version: 1.22.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9313140
36
- description: ! "forj command line arguments is an aggregation, in priority order,
37
- of\n command line arguments, environment variables, forj.yaml
38
- config file"
35
+ version_requirements: *15156540
36
+ description: forj command line
39
37
  email:
40
38
  - forj@forj.io
41
39
  executables:
@@ -49,6 +47,12 @@ files:
49
47
  - lib/network.rb
50
48
  - lib/security.rb
51
49
  - lib/yaml_parse.rb
50
+ - lib/catalog.yaml
51
+ - lib/down.rb
52
+ - lib/boot.rb
53
+ - lib/setup.rb
54
+ - lib/version.rb
55
+ - lib/repositories.rb
52
56
  homepage: https://forj.io
53
57
  licenses:
54
58
  - APACHE
@@ -73,5 +77,5 @@ rubyforge_project:
73
77
  rubygems_version: 1.8.11
74
78
  signing_key:
75
79
  specification_version: 3
76
- summary: forj cli
80
+ summary: forj command line
77
81
  test_files: []