forj 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/forj +85 -0
- data/lib/compute.rb +72 -0
- data/lib/connection.rb +67 -0
- data/lib/network.rb +117 -0
- data/lib/security.rb +68 -0
- data/lib/yaml_parse.rb +23 -0
- metadata +77 -0
data/bin/forj
ADDED
@@ -0,0 +1,85 @@
|
|
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 'thor'
|
18
|
+
|
19
|
+
require_relative '../lib/boot.rb'
|
20
|
+
include Boot
|
21
|
+
require_relative '../lib/down.rb'
|
22
|
+
include Down
|
23
|
+
require_relative '../lib/version.rb'
|
24
|
+
include Version
|
25
|
+
require_relative '../lib/setup.rb'
|
26
|
+
include Setup
|
27
|
+
|
28
|
+
|
29
|
+
class Forj < Thor
|
30
|
+
|
31
|
+
desc 'help', 'Display forj cli help'
|
32
|
+
def help
|
33
|
+
puts 'forj cli commands'
|
34
|
+
puts ' -action:'
|
35
|
+
puts ' boot: boot a Maestro box and instruct it to provision the blueprint'
|
36
|
+
puts ' -blueprint: which blueprint to use'
|
37
|
+
puts ' -on: just because :)'
|
38
|
+
puts ' -cloud_provider: cloud provider type to be used to provision the forge.'
|
39
|
+
puts ' - hpcloud: uses HP public cloud http://hpcloud.com/'
|
40
|
+
puts ' - openstack: OpenStack based private or public cloud'
|
41
|
+
puts ' - more to come'
|
42
|
+
puts ' -as: just because :)'
|
43
|
+
puts ' -name: name for the maestro box'
|
44
|
+
puts ' down: delete the Maestro box and all systems installed by the blueprint'
|
45
|
+
puts ' setup: set the credentials for forj cli'
|
46
|
+
puts ' version: display the version of forj cli'
|
47
|
+
puts ''
|
48
|
+
puts ' -credentials:'
|
49
|
+
puts ' hpcloud:'
|
50
|
+
puts ' access_key: access key from hpcloud'
|
51
|
+
puts ' secret_key: secret key from hpcloud'
|
52
|
+
puts ' auth_uri: identity endpoint'
|
53
|
+
puts ' tenant_id: id for the tenant you want to use'
|
54
|
+
puts ' availability_zone: which availability zone will be deployed'
|
55
|
+
puts ''
|
56
|
+
puts ' openstack:'
|
57
|
+
puts ' openstack_username: your openstack username'
|
58
|
+
puts ' openstack_api_key: your openstack password'
|
59
|
+
puts ' openstack_auth_url: your openstack identity endpoint'
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'boot', 'boot a Maestro box and instruct it to provision the blueprint'
|
63
|
+
def boot(blueprint, on, cloud_provider, as, name, test=false)
|
64
|
+
Boot.boot(blueprint, cloud_provider,name , test)
|
65
|
+
end
|
66
|
+
|
67
|
+
desc 'down', 'delete the Maestro box and all systems installed by the blueprint'
|
68
|
+
def down(name)
|
69
|
+
Down.down(name)
|
70
|
+
end
|
71
|
+
|
72
|
+
desc 'version', 'get the current version of forj cli'
|
73
|
+
def version
|
74
|
+
VERSION.version
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'setup', 'set the credentials for forj cli'
|
78
|
+
def setup
|
79
|
+
Setup.setup
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
Forj.start
|
data/lib/compute.rb
ADDED
@@ -0,0 +1,72 @@
|
|
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 'net/http'
|
18
|
+
require 'open-uri'
|
19
|
+
|
20
|
+
require_relative 'connection.rb'
|
21
|
+
include Connection
|
22
|
+
|
23
|
+
module Compute
|
24
|
+
|
25
|
+
def get_image(image_name)
|
26
|
+
compute = Connection.compute
|
27
|
+
|
28
|
+
images = compute.images.all
|
29
|
+
image = nil
|
30
|
+
|
31
|
+
for i in images do
|
32
|
+
if i.name == image_name
|
33
|
+
image = i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
image
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_flavor(flavor_name)
|
40
|
+
compute = Connection.compute
|
41
|
+
|
42
|
+
flavors = compute.flavors.all
|
43
|
+
flavor = nil
|
44
|
+
|
45
|
+
for f in flavors do
|
46
|
+
if f.name == flavor_name
|
47
|
+
flavor = f
|
48
|
+
end
|
49
|
+
end
|
50
|
+
flavor
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_instance(name, flavor_id, image_id, key_name, security_groups, availability_zone, networks)
|
54
|
+
server = Connection.compute.servers.create(
|
55
|
+
:name => name,
|
56
|
+
:flavor_id => flavor_id,
|
57
|
+
:image_id => image_id,
|
58
|
+
:key_name => key_name,
|
59
|
+
:security_groups => [security_groups],
|
60
|
+
:availability_zone => availability_zone,
|
61
|
+
:networks => [networks],
|
62
|
+
:metadata => { :Meta1 => 'MetaValue1'},
|
63
|
+
:config_drive => true
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete_instance(maestro)
|
68
|
+
maestro = Connection.compute.servers.all(:name => maestro)[0]
|
69
|
+
Connection.compute.servers.get(maestro.id).destroy
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/lib/connection.rb
ADDED
@@ -0,0 +1,67 @@
|
|
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 'fog'
|
18
|
+
|
19
|
+
require_relative 'yaml_parse.rb'
|
20
|
+
include YamlParse
|
21
|
+
|
22
|
+
module Connection
|
23
|
+
|
24
|
+
def compute
|
25
|
+
credentials = get_credentials
|
26
|
+
compute = Fog::Compute.new ({
|
27
|
+
:provider => 'HP',
|
28
|
+
:hp_access_key => credentials['access_key'],
|
29
|
+
:hp_secret_key => credentials['secret_key'],
|
30
|
+
:hp_auth_uri => credentials['auth_uri'],
|
31
|
+
:hp_tenant_id => credentials['tenant_id'],
|
32
|
+
:hp_avl_zone => credentials['availability_zone'],
|
33
|
+
:version => 'v2'
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def network
|
38
|
+
credentials = get_credentials
|
39
|
+
network = Fog::HP::Network.new ({
|
40
|
+
:hp_access_key => credentials['access_key'],
|
41
|
+
:hp_secret_key => credentials['secret_key'],
|
42
|
+
:hp_auth_uri => credentials['auth_uri'],
|
43
|
+
:hp_tenant_id => credentials['tenant_id'],
|
44
|
+
:hp_avl_zone => credentials['availability_zone'],
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_credentials
|
51
|
+
home = File.expand_path('~')
|
52
|
+
file = home + '/.hpcloud'
|
53
|
+
template = YAML.load_file(file)
|
54
|
+
credentials = Hash.new
|
55
|
+
|
56
|
+
begin
|
57
|
+
credentials['access_key'] = template['default']['access_key']
|
58
|
+
credentials['secret_key'] = template['default']['secret_key']
|
59
|
+
credentials['auth_uri'] = template['default']['auth_uri']
|
60
|
+
credentials['tenant_id'] = template['default']['tenant_id']
|
61
|
+
credentials['availability_zone'] = template['default']['availability_zone']
|
62
|
+
rescue
|
63
|
+
puts 'your credentials are not configured, delete the file %s and run forj setup again' % [file]
|
64
|
+
end
|
65
|
+
|
66
|
+
credentials
|
67
|
+
end
|
data/lib/network.rb
ADDED
@@ -0,0 +1,117 @@
|
|
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 'connection.rb'
|
18
|
+
include Connection
|
19
|
+
|
20
|
+
module Network
|
21
|
+
|
22
|
+
def create_network(name)
|
23
|
+
network = Connection.network.networks.create(:name => name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_network(network_name)
|
27
|
+
network = Connection.network.networks.all(:name => network_name)[0]
|
28
|
+
Connection.network.networks.get(network.id).destroy
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_subnet(network_id, name)
|
32
|
+
subnet = Connection.network.subnets.create(
|
33
|
+
:network_id => network_id,
|
34
|
+
:name => name,
|
35
|
+
:cidr => get_next_subnet,
|
36
|
+
:ip_version => '4'
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_subnet(subnet_id)
|
41
|
+
Connection.network.subnets.get(subnet_id).destroy
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_subnet(name)
|
45
|
+
subnet = Connection.network.subnets.all(:name => name)[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_router(name)
|
49
|
+
routers = Connection.network.routers.all({:name => name})
|
50
|
+
router = nil
|
51
|
+
for r in routers do
|
52
|
+
router = r
|
53
|
+
end
|
54
|
+
router
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_router_interface(subnet_id, router)
|
58
|
+
interface = router.add_interface(subnet_id, nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete_router_interface(subnet_id, router)
|
62
|
+
router.remove_interface(subnet_id)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_router(name)
|
66
|
+
router = Connection.network.routers.create(
|
67
|
+
:name => name,
|
68
|
+
:admin_state_up => true
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete_router(router_id)
|
73
|
+
Connection.network.routers.get(router_id).destroy
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def get_next_subnet
|
80
|
+
subnet_values = Array.new
|
81
|
+
subnets = Connection.network.subnets.all
|
82
|
+
for s in subnets do
|
83
|
+
subnet_values.push(s.cidr)
|
84
|
+
end
|
85
|
+
|
86
|
+
gap = false
|
87
|
+
count = 0
|
88
|
+
range_used = Array.new
|
89
|
+
new_subnet = 0
|
90
|
+
new_cidr = ''
|
91
|
+
|
92
|
+
subnet_values = subnet_values.sort!
|
93
|
+
|
94
|
+
for value in subnet_values
|
95
|
+
range_used.push(value[5])
|
96
|
+
end
|
97
|
+
|
98
|
+
for n in range_used
|
99
|
+
if count.to_i == n.to_i
|
100
|
+
else
|
101
|
+
new_subnet = count
|
102
|
+
gap = true
|
103
|
+
break
|
104
|
+
end
|
105
|
+
count += 1
|
106
|
+
end
|
107
|
+
|
108
|
+
if gap
|
109
|
+
new_cidr = '10.0.%s.0/24' % [count]
|
110
|
+
else
|
111
|
+
max_value = range_used.max
|
112
|
+
new_subnet = max_value.to_i + 1
|
113
|
+
new_cidr = '10.0.%s.0/24' % [new_subnet]
|
114
|
+
end
|
115
|
+
new_cidr
|
116
|
+
|
117
|
+
end
|
data/lib/security.rb
ADDED
@@ -0,0 +1,68 @@
|
|
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 'connection.rb'
|
18
|
+
include Connection
|
19
|
+
|
20
|
+
# create a security group for each blueprint
|
21
|
+
|
22
|
+
module SecurityGroup
|
23
|
+
|
24
|
+
def create_security_group(name)
|
25
|
+
security_groups = Connection.network.security_groups.all({:name => name})
|
26
|
+
security_group = nil
|
27
|
+
|
28
|
+
if security_groups.length >= 1
|
29
|
+
security_group = security_groups[0]
|
30
|
+
else
|
31
|
+
description = 'Security group for blueprint %s' % [name]
|
32
|
+
security_group = Connection.network.security_groups.create(
|
33
|
+
:name => name,
|
34
|
+
:description => description
|
35
|
+
)
|
36
|
+
end
|
37
|
+
security_group
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_security_group(security_group_id)
|
41
|
+
Connection.network.security_groups.get(security_group_id).destroy
|
42
|
+
end
|
43
|
+
|
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
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_security_group_rule(rule_id)
|
56
|
+
Connection.network.security_group_rules.get(rule_id).destroy
|
57
|
+
end
|
58
|
+
|
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
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/lib/yaml_parse.rb
ADDED
@@ -0,0 +1,23 @@
|
|
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 'yaml'
|
18
|
+
|
19
|
+
module YamlParse
|
20
|
+
def get_values(path_to_yaml)
|
21
|
+
template = YAML.load_file(path_to_yaml)
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: forj
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- forj team
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &9313720 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.22.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *9313720
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fog
|
27
|
+
requirement: &9313140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.19'
|
33
|
+
type: :runtime
|
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"
|
39
|
+
email:
|
40
|
+
- forj@forj.io
|
41
|
+
executables:
|
42
|
+
- forj
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- bin/forj
|
47
|
+
- lib/compute.rb
|
48
|
+
- lib/connection.rb
|
49
|
+
- lib/network.rb
|
50
|
+
- lib/security.rb
|
51
|
+
- lib/yaml_parse.rb
|
52
|
+
homepage: https://forj.io
|
53
|
+
licenses:
|
54
|
+
- APACHE
|
55
|
+
post_install_message: Go to docs.forj.io for more information on how to use forj cli
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.8.6
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.11
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: forj cli
|
77
|
+
test_files: []
|