forj 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.md +0 -3
  2. data/bin/forj +40 -26
  3. data/lib/catalog.yaml +1 -0
  4. data/lib/ssh.rb +15 -2
  5. data/lib/ssh.sh +183 -0
  6. metadata +14 -13
data/README.md CHANGED
@@ -6,9 +6,6 @@ How to use it
6
6
  =====================
7
7
 
8
8
 
9
- FORJ Team
10
-
11
-
12
9
  Contributing to Forj
13
10
  =====================
14
11
  We welcome all types of contributions. Checkout our website (http://docs.forj.io/en/latest/dev/contribute.html)
data/bin/forj CHANGED
@@ -32,30 +32,44 @@ include Ssh
32
32
  class Forj < Thor
33
33
  desc 'help', 'Display forj cli help'
34
34
  def help
35
- puts 'forj cli commands'
36
- puts ' -action:'
37
- puts ' boot: boot a Maestro box and instruct it to provision the blueprint'
38
- puts ' -blueprint: which blueprint to use'
39
- puts ' -on: just because :)'
40
- puts ' -cloud_provider: cloud provider type to be used to provision the forge.'
41
- puts ' - hpcloud: uses HP public cloud http://hpcloud.com/'
42
- puts ' - openstack: OpenStack based private or public cloud'
43
- puts ' - more to come'
44
- puts ' -as: just because :)'
45
- puts ' -name: name for the maestro box'
46
- puts ' -test: this will delete everything after it finish to install the forge'
47
- puts ' example: forj boot redstone on hpcloud as redstone01'
48
- puts ' down: delete the Maestro box and all systems installed by the blueprint'
49
- puts ' -name: name for the maestro box'
50
- puts ' setup: set the credentials for forj cli'
51
- puts ' -credentials:'
52
- puts ' hpcloud:'
53
- puts ' access_key: access key from hpcloud'
54
- puts ' secret_key: secret key from hpcloud'
55
- puts ' auth_uri: identity endpoint'
56
- puts ' tenant_id: id for the tenant you want to use'
57
- puts ' availability_zone: which availability zone will be deployed'
35
+ puts 'Forj cli help'
58
36
  puts ''
37
+ puts ' forj setup # Set the credentials for forj.'
38
+ puts ' required credentials:'
39
+ puts ' access_key: access key from hpcloud'
40
+ puts ' secret_key: secret key from hpcloud'
41
+ puts ' auth_uri: identity endpoint'
42
+ puts ' tenant_id: id for the tenant you want to use'
43
+ puts ' availability_zone: which availability zone will be deployed'
44
+ puts ''
45
+ puts ' forj boot # Boot a new forge with the following options'
46
+ puts ' required:'
47
+ puts ' blueprint: name of the blueprint (currently cli only supports redstone)'
48
+ puts ' on: just to have a natural description'
49
+ puts ' cloud_provider: in which cloud provider to deploy the forge'
50
+ puts ' as: just to have a natural description'
51
+ puts ' name: name of the forge'
52
+ puts ' example:'
53
+ puts ' forj boot redstone on hpcloud as maestro_test'
54
+ puts ' optional:'
55
+ puts ' -b build: replace the default build.sh'
56
+ puts ' -bcd build_config_dir: defines the build configuration directory to load the build configuration file'
57
+ puts ' -bc build_config: the build config file to load <confdir>/<BoxName>.<Config>.env.'
58
+ puts ' -gb branch: the build will extract from git branch name'
59
+ puts ' -tb test_box (not yet implemented): create test-box meta from the repository path provided.'
60
+ puts ' -gr git_repo: the box built will use a different git repository sent out to <user_data>'
61
+ puts ' -bh boothook: by default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.'
62
+ puts ' -bn box_name: defines the name of the box or box image to build.'
63
+ puts ''
64
+ puts ' forj ssh # Connect through ssh to an existing instance'
65
+ puts ' required:'
66
+ puts ' name: name of the forge (maestro_test)'
67
+ puts ' node: name of the node (maestro, ci, etc...)'
68
+ puts ''
69
+ puts ' forj down # Delete a forge and create a backup of your data'
70
+ puts ' not yet implemented'
71
+ puts ''
72
+ puts ' forj help # Display this help'
59
73
  end
60
74
 
61
75
  desc 'boot', 'boot a Maestro box and instruct it to provision the blueprint'
@@ -66,7 +80,7 @@ class Forj < Thor
66
80
  method_option :branch, :aliases => '-gb', :desc => 'The build will extract from git branch name. It sets the configuration build <config> to the branch name <branch>.'
67
81
  method_option :test_box, :aliases => '-tb', :desc => 'Create test-box meta from the repository path provided.'
68
82
  method_option :git_repo, :aliases => '-gr', :desc => 'The box built will use a different git repository sent out to <user_data>. This repository needs to be read only. No keys are sent.'
69
- method_option :boothook, :aliases => '-b', :desc => 'By default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.'
83
+ method_option :boothook, :aliases => '-bh', :desc => 'By default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.'
70
84
  method_option :box_name, :aliases => '-bn', :desc => 'Defines the name of the box or box image to build.'
71
85
 
72
86
  def boot(blueprint, on, cloud_provider, as, name, test = false)
@@ -83,8 +97,8 @@ class Forj < Thor
83
97
  end
84
98
 
85
99
  desc 'ssh', 'connect to your forge thru ssh'
86
- def ssh
87
- Ssh.connect
100
+ def ssh(name, server)
101
+ Ssh.connect(name, server)
88
102
  end
89
103
 
90
104
  desc 'setup', 'set the credentials for forj cli'
data/lib/catalog.yaml CHANGED
@@ -18,6 +18,7 @@ redstone:
18
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
+ nodes: [maestro, ci, util, review]
21
22
 
22
23
  modus:
23
24
  ports: []
data/lib/ssh.rb CHANGED
@@ -15,11 +15,24 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
+ require 'rubygems'
19
+ require 'require_relative'
20
+
18
21
  #
19
22
  # ssh module
20
23
  #
21
24
  module Ssh
22
- def connect
23
- puts 'ssh'
25
+ def connect(name, server)
26
+ current_dir = Dir.pwd
27
+ Dir.chdir(current_dir + '/lib')
28
+
29
+ update = './ssh.sh -u'
30
+ connection = './ssh.sh %s %s' % [name, server]
31
+
32
+ # update the list of servers
33
+ Kernel.system(update)
34
+
35
+ # connect to the server
36
+ Kernel.system(connection)
24
37
  end
25
38
  end
data/lib/ssh.sh ADDED
@@ -0,0 +1,183 @@
1
+ #!/bin/bash
2
+ #vim: setlocal ft=sh:
3
+ RST="\e[0m"
4
+ RED="\e[31m"
5
+ BLU="\e[34m"
6
+ GRE="\e[92m"
7
+
8
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+ OW=`date +%Y-%m-%d.%H%M%S`
23
+ logpath=~/.ssh/
24
+ DB=~/hosts
25
+ key_path=~/.ssh/
26
+ init_config=~/ssh_init
27
+ key="nova"
28
+
29
+ if [ ! -f $DB ]; then
30
+ cat > $DB <<'EOF'
31
+
32
+ #Custom Servers - (Won't be deleted when updating list)
33
+ #<name.id> <public ip> <date> <key>
34
+
35
+ #### Below list are updated
36
+
37
+ EOF
38
+ fi
39
+
40
+ ##No parameters sent
41
+ if (( $# < 1 )); then
42
+ echo -e "${RED}Error, no parameter was sent.$RST"
43
+ echo "Use this script as:"
44
+ echo " -rm <id> : Removes all nodes that match the id."
45
+ echo " -f <text>: Finds the text in the log files."
46
+ echo " -u : Updates the hosts list querying nova server."
47
+ echo " -l : Lists the current hosts."
48
+ echo " <IP> : Connects directly to the IP using default key"
49
+ echo "<id> <name>: Queries the hosts list looking for the id and name."
50
+ echo -e "\n ${GRE}OPTIONS${RST}"
51
+ echo " -i {par} : Applies initialization script to the server."
52
+ exit 1
53
+ fi
54
+
55
+ if [ $1 == '-i' ]; then
56
+ if [ ! -f $init_config ]; then
57
+ echo "${RED}Error, config file: $init_config does not exists."
58
+ exit 1
59
+ fi
60
+ shift
61
+ is_init='true'
62
+ fi
63
+
64
+ #Finds text in logs
65
+ if [ $1 == '-f' ]; then
66
+ grep --include=*.log -rnw $logpath -e "$2" --color=always
67
+ exit 0
68
+ fi
69
+
70
+ if [ $1 == '-rm' ] && [ "$2" != '' ]; then
71
+ echo "Removing $2..."
72
+ cat $DB | grep -iE "[a-z]+\.$2" --color=always
73
+ sed -i -E "/[a-z]+\.$2/d" $DB
74
+ exit 0
75
+ fi
76
+
77
+ ##Just Lists the hosts db
78
+ if [ $1 == '-l' ]; then
79
+ echo "List of hosts:"
80
+ if [ "$2" != "" ]; then #kit
81
+ result=$(cat $DB | grep -iE "\.$2" --color=always)
82
+ else #All Maestros
83
+ result=$(cat $DB | grep -E "maestro\.")
84
+ fi
85
+ echo "$result"
86
+ exit 0
87
+ fi
88
+
89
+ ##Just list the hosts db
90
+ if [ $1 == '-u' ]; then
91
+ linenum=$(cat $DB | grep -E -n "#### Below list are updated" | awk -F: '{print $1}')
92
+ old_serversnum=$(tail -n +$linenum $DB | grep -E " .*\..* " | wc -l)
93
+
94
+ sed -i -n '/\#\#\#\# Below list are updated/q;p' $DB
95
+ sed -i '/^$/d' $DB
96
+ echo -e "\n#### Below list are updated" >> $DB
97
+
98
+ hpcloud servers | awk -F"\|" '{print $3","$6","$9","$7}' | awk -F, '{print $1$3$4$5}' >> $DB
99
+ echo -e "\033[1;32m$DB Updated\033[00m"
100
+ linenum=$(cat $DB | grep -E -n "#### Below list are updated" | awk -F: '{print $1}')
101
+ new_serversnum=$(tail -n +$linenum $DB | grep -E " .*\..* " | wc -l)
102
+ diff=$(echo "$new_serversnum - $old_serversnum" | bc)
103
+ echo "Old Servers: $old_serversnum, New Servers: $new_serversnum, Diff: $diff"
104
+ exit 0
105
+ fi
106
+
107
+ #parameter is IP
108
+ if [[ $1 =~ ([0-9]{1,3}\.){3}[0-9]{1,3} ]]; then
109
+ ip=$1
110
+ #Check if has URL and clean it if so
111
+ if [[ $ip =~ 'http' ]]; then
112
+ ip=$(echo "$ip" | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}')
113
+ fi
114
+ #Check if IP exists in db and show info
115
+ host_name=$(cat $DB | grep $ip | awk '{print $1}')
116
+ if [[ "$host_name" != "" ]]; then
117
+ echo -e "Host: \033[33m$host_name${RST}"
118
+ fi
119
+ message="$ip"
120
+ #parameter is ID NODE
121
+ else
122
+ id=$1
123
+ node=$2
124
+
125
+ if [ "$node" == "" ]; then
126
+ echo -e "${RED}Error, no server name sent.$RST"
127
+ exit 1
128
+ fi
129
+
130
+ #Alias handling
131
+ alias=$(cat ~/hosts | grep -iE '^alias:' | grep -iE ' '$node | awk '{print $2}')
132
+ if [ "$alias" != "" ] && [ "$alias" != "$node" ]; then
133
+ echo "Using alias $node, converting to $alias"
134
+ node=$alias
135
+ fi
136
+
137
+ ip=$(cat $DB | grep -iE "[a-ZA-Z]+\.$id" | grep -i $node | awk '{print $2}' | tr -d ' ')
138
+ if [ "$ip" == "" ]; then
139
+ echo -e "${RED}Error, the kit ${GRE}$node${RED} with id ${GRE}$id${RED} was not found.${RST}"
140
+ exit 1
141
+ fi
142
+ key=$(cat $DB | grep -iE "$ip" | awk '{print $4}' | tr -d ' ')
143
+ message="$node.$id"
144
+ extended="($ip)"
145
+
146
+ if [ "$ip" == "" ] || [ "$key" == "" ]; then
147
+ echo -e "${RED}Error, combination was not found, maybe you should update the db.$RST"
148
+ exit 1
149
+ fi
150
+ fi
151
+
152
+ if [ "$node" != "" ]; then
153
+ logname="$node.$id"
154
+ else
155
+ logname="$ip"
156
+ fi
157
+ key="$key_path$key.pem"
158
+
159
+ echo -e "Connecting to $GRE$message$RST using $BLU$key$RST $extended"
160
+
161
+ if [[ ! -f $key ]]; then
162
+ echo -e "${RED}Key doesn't exists$RST"
163
+ exit 1
164
+ fi
165
+
166
+ logfile="${logpath}sshlog.$logname.$NOW.log"
167
+
168
+ echo -e "$RED══════════════════════════════════════════════════════════════════════════$RST"
169
+ #echo "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=180 -i $key ubuntu@$ip"
170
+ if [ "$is_init" == 'true' ]; then
171
+ username=$(id -u -n)
172
+ username=${username^^} #convert to upper
173
+ grep -q "$username" $init_config
174
+ if [ $? != 0 ]; then
175
+ echo "Writing username to $init_config file."
176
+ sed -i "s/^owner='.*'$/owner='$username'/g" $DB
177
+ fi
178
+ ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=180 -i $key ubuntu@$ip < $init_config
179
+ echo -e "Reconnecting..."
180
+ fi
181
+ ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=180 -i $key ubuntu@$ip | tee -a $logfile
182
+ echo -e "$RED══════════════════════════════════════════════════════════════════════════$RST"
183
+ echo -e "${GRE}Log file: ${RST}$logfile"
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.28
4
+ version: 0.0.29
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: &11546020 !ruby/object:Gem::Requirement
16
+ requirement: &12934080 !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: *11546020
24
+ version_requirements: *12934080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &11543820 !ruby/object:Gem::Requirement
27
+ requirement: &12933440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.11
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11543820
35
+ version_requirements: *12933440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fog
38
- requirement: &11542840 !ruby/object:Gem::Requirement
38
+ requirement: &12932840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.19.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *11542840
46
+ version_requirements: *12932840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hpcloud
49
- requirement: &11541880 !ruby/object:Gem::Requirement
49
+ requirement: &12932140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.0.8
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *11541880
57
+ version_requirements: *12932140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: git
60
- requirement: &11540940 !ruby/object:Gem::Requirement
60
+ requirement: &12931320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.2.7
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *11540940
68
+ version_requirements: *12931320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rbx-require-relative
71
- requirement: &11537200 !ruby/object:Gem::Requirement
71
+ requirement: &12930460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.0.7
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *11537200
79
+ version_requirements: *12930460
80
80
  description: forj command line
81
81
  email:
82
82
  - forj@forj.io
@@ -96,6 +96,7 @@ files:
96
96
  - lib/setup.rb
97
97
  - lib/repositories.rb
98
98
  - lib/ssh.rb
99
+ - lib/ssh.sh
99
100
  - lib/log.rb
100
101
  - lib/helpers.rb
101
102
  - spec/boot_spec.rb