forj 0.0.33 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d116642b62ded0c9f2aa26a8f3d67acf73a45d3
4
+ data.tar.gz: 81d3018544a5e3a211dbaf72110815cddbd0c503
5
+ SHA512:
6
+ metadata.gz: e80b51b75742c2288a3351aca10d79438f94e8ce02713f14d956cadd135bfc29e9b4d8e9e90a5104ea90bb6f438c3afc4f5684989726a7cafa4cb0d47bd3d129
7
+ data.tar.gz: b2e2fddb8b5dbe3410f22606eb248f43f0152b83b89c0a7a7f9643f0f385e0bdcd544e7aa8cd1f02b4fcf79617322914eb75ef1716d583ae59c799ac66c7c6e5
data/README.md CHANGED
@@ -1,82 +1,109 @@
1
1
  Forj cli
2
- =====================
2
+ ========
3
3
 
4
4
 
5
5
  Installation
6
- =====================
7
- For ruby 2.0
6
+ ------------
7
+ ### For ruby 2.0
8
8
 
9
- Fedora/CentOS/Redhat/rpm like system
9
+ **Fedora/CentOS/Redhat rpm like package system**
10
10
 
11
- sudo yum install ruby-dev build-essential libopenssl-ruby libssl-dev zlib1g-dev -y
12
- sudo gem install forj
11
+ $ sudo yum install ruby-devel libxml2-devel libxslt-devel python-yaml -y
12
+ $ sudo gem install forj
13
13
 
14
- Ubuntu/Debian/debian like system (not tested)
14
+ **Ubuntu/Debian deb like package system (not tested)**
15
15
 
16
- sudo apt-get install ruby-dev build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev -y
17
- sudo gem install forj
16
+ $ sudo apt-get install ruby-dev build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev -y
17
+ $ sudo gem install forj
18
18
 
19
- For ruby 1.9
19
+ ### For ruby 1.9
20
20
 
21
- sudo apt-get install ruby-dev build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev -y
22
- sudo gem install forj
21
+ $ sudo apt-get install ruby-dev build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev -y
22
+ $ sudo gem install forj
23
23
 
24
- For ruby 1.8
24
+ ### For ruby 1.8
25
25
 
26
- sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 -y
27
- sudo apt-get install libreadline-ruby1.8 libruby1.8 libopenssl-ruby -y
28
- sudo apt-get install libxslt-dev libxml2-dev -y
29
- sudo gem install nokogiri
30
- sudo apt-get install ruby-bundler -y
31
- sudo gem install mime-types -v 1.25.1
32
- sudo gem install hpcloud
33
- sudo gem install forj
26
+ $ sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 -y
27
+ $ sudo apt-get install libreadline-ruby1.8 libruby1.8 libopenssl-ruby -y
28
+ $ sudo apt-get install libxslt-dev libxml2-dev -y
29
+ $ sudo gem install nokogiri
30
+ $ sudo apt-get install ruby-bundler -y
31
+ $ sudo gem install mime-types -v 1.25.1
32
+ $ sudo gem install hpcloud
33
+ $ sudo gem install forj
34
34
 
35
35
 
36
- How to use forj cli
37
- =====================
38
- Setup forj
36
+ Quick steps: How to create a forj?
37
+ ----------------------------------
39
38
 
40
39
  forj setup # follow the instructions
41
40
 
42
- Boot a forge
43
-
44
- forj boot <blueprint> on <cloud_provider> as <name>
45
- e.g. forj boot redstone on hpcloud as maestro_01
46
-
47
- Optional arguments
48
-
49
- -u --build #Replace the default build.sh.
50
- -d --build_config_dir # Defines the build configuration directory to load the build configuration file.
51
- -c --build_config # The build config file to load <confdir>/<BoxName>.<Config>.env.
52
- -b --branch # The build will extract from git branch name.
53
- -t --test_box # Create test-box meta from the repository path provided.
54
- -r --git_repo # The box built will use a different git repository sent out to <user_data>.
55
- -h --boothook # By default, boothook file used is build/bin/build-tools/boothook.sh.
56
- -x --box_name # Defines the name of the box or box image to build.
57
- -k --key_name # Key pair name to import.
58
- -p --key_path # Public key pair data.
59
- -y --catalog # A path for the yaml file data about the blueprint
60
-
61
- Catalog.yaml example
62
-
63
- redstone:
64
- image: proto2b
65
- flavor: standard.xsmall
66
- 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]
67
- keypair_path: ~/.hpcloud/keypairs/nova
68
- keypair_name: nova
69
- router: private-ext
70
- security_group: default
71
- network: private
72
- # at this point you have to clone the infra project manually
73
- build_config_dir: ~/forj/infra/build/boxes/maestro
74
- build_config: box-13.5
75
- branch: master
76
- box_name: maestro
77
- infra: ~/.forj/infra
78
- default:
79
- maestro: https://github.com/forj-oss/maestro.git
41
+ 1. Setup your first forj account.
42
+
43
+ `$ forj setup [Provider]`
44
+
45
+ Ex: `forj setup hpcloud`. In this example, your account will be named 'hpcloud'.
46
+ **WARNING!!!** [Provider] is currently not supported. By default, it is using hpcloud as default provider.
47
+
48
+ 2. Create your forge on your default account
49
+
50
+ `$ forj boot <blueprint> on hpcloud as <InstanceName>`
51
+
52
+ Ex: `forj boot redstone on hpcloud as MyForge`
53
+
54
+
55
+ ###Forj options:
56
+
57
+ To get forj cli help, just type:
58
+
59
+ $ forj
60
+
61
+ To get help on specific action, just type:
62
+
63
+ $ forj help boot
64
+
65
+ Examples of possible actions:
66
+
67
+ Commands:
68
+ forj boot <Blueprint> on <Provider> as <InstanceName> [options] # boot a Maestro box and instruct it to provision the blueprint
69
+ forj down # delete the Maestro box and all systems installed by the blueprint
70
+ forj help [action] # Describe available FORJ actions or one specific action
71
+ forj setup # set the credentials for forj cli
72
+ forj show defaults # Show list of predefined value you can update in your ~/.forj/config.yaml
73
+ forj ssh
74
+
75
+
76
+ #### config.yaml description
77
+
78
+ While building your forge, forj needs to load some data by default. Those are listed in forj-<version>/lib/defaults.yaml
79
+
80
+ If you need to change one of this default value, update a ~/.forj/config.yaml file, with any kind of data that need to be changed.
81
+
82
+ Here are the variables list you can set:
83
+
84
+ default:
85
+ account_name: name # Default forj account used to connect to your cloud. This setting is automatically set to the first account created with forj setup <CloudProvider>
86
+ maestro_url: url # Maestro GIT repository for clone.
87
+ infra_repo: path # Path to the default Infra repository used to store your specific bootstrap/build environment. By default: ~/.forj/infra
88
+ image: imageName # NOT CURRENTLY USED. Still under development.
89
+ # Image used to create Maestro and all forge boxes. By default, it is 'Ubuntu Precise 12.04.4 LTS Server 64-bit 20140414 (Rescue Image)'
90
+ # If you have created the generic proto2b image, you can set it here.
91
+ flavor: flavorName # NOT CURRENTLY USED. Still under development.
92
+ # Maestro Flavor name. This flavor is for Maestro only. Your blueprint layout defines each node flavors on needs.
93
+ # By default: standard.xsmall
94
+ ports: [Port1,Port2,...] # list of additional ports to add in your cloud security group.
95
+ # This list is added to the default one in defaults.yaml
96
+ keypair_path: path # Define the file path to your OpenSSH private key. Useful to access your box with ssh command line.
97
+ # By default. ~/.forj/keypairs/nova
98
+ keypair_name: name # keypair name defined in your cloud to access your server. By default we named it 'nova'. If it doesn't exist, it will be created.
99
+ router: name # Router name used by your forge boxes will use to access internet.
100
+ security_group: name # Security group name to configure and attach to each forge boxes.
101
+ network: name # Network name to attach to each forge boxes. By default we use 'private'. If it doesn't exist, it will be created.
102
+ # Internal use.
103
+ build_config: name # forj cli use 'build.sh' to create Maestro. See build_config option on build.sh to get more information. By default 'box'
104
+ branch: name # forj cli use 'build.sh' to create Maestro. See gitbranch option on build.sh to get more information. By default 'master'
105
+ box_name: maestro # forj cli use 'build.sh' to create Maestro. See box_name option on build.sh to get more information. By default 'maestro'
106
+
80
107
  To ssh into a server
81
108
 
82
109
  forj ssh <name> <node>
@@ -89,6 +116,49 @@ We welcome all types of contributions. Checkout our website (http://docs.forj.i
89
116
  to start hacking on Forj. Also join us in our community (https://www.forj.io/community/) to help grow and foster Forj for
90
117
  your development today!
91
118
 
92
- License
93
- =====================
119
+
120
+ Developping on FORJ:
121
+ ===================
122
+
123
+ Development installation:
124
+ -------------------------
125
+
126
+ **WARNING!!!** forj cli is still under intensive development.
127
+
128
+ ### For ruby 2.0
129
+
130
+ **Fedora/CentOS/Redhat rpm like package system**
131
+
132
+ $ sudo yum install git gcc ruby-devel libxml2-devel rubygem-rspec libxslt-devel python-yaml rubygem-nokogiri -y
133
+ $ gem install rspec-rake rspec-mocks rspec-expectations
134
+
135
+ **Ubuntu/Debian deb like package system (not tested)**
136
+
137
+ $ sudo apt-get install git ruby-dev build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev -y
138
+ $ gem install rspec rspec-rake rspec-mocks rspec-expectations
139
+
140
+ Then execute the following:
141
+
142
+ $ gem install forj # To install all gem required for running it.
143
+ $ mkdir -p ~/src/forj-oss
144
+ $ cd ~/src/forj-oss
145
+ $ git clone https://github.com/forj-oss/cli
146
+
147
+ To update `forj` from the repository:
148
+
149
+ $ cd ~/src/forj-oss/cli
150
+ $ git pull
151
+
152
+ To test `forj` cli, do the following:
153
+
154
+ $ cd ~/src/forj-oss/cli
155
+ $ bin/forj
156
+
157
+ To run unit-test, do the following:
158
+
159
+ $ cd ~/src/forj-oss/cli
160
+ $ rspec -c
161
+
162
+ License:
163
+ ========
94
164
  Forj Cli is licensed under the Apache License, Version 2.0. See LICENSE for full license text.
data/bin/forj CHANGED
@@ -28,63 +28,75 @@ include Setup
28
28
  require_relative '../lib/ssh.rb'
29
29
  include Ssh
30
30
 
31
+ $APP_PATH = File.dirname(__FILE__)
32
+ $LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
33
+
34
+ $FORJ_DATA_PATH= File.expand_path('~/.forj')
35
+ $LOAD_PATH << './lib'
36
+
37
+ require 'forj-config.rb' # Load class ForjConfig
31
38
 
32
39
  class Forj < Thor
33
- desc 'help', 'Display forj cli help'
34
- def help
35
- puts 'Forj cli help'
36
- puts ''
37
- puts ' forj setup # Set the credentials for forj. Currently supports only hpcloud provider.'
38
- puts ' Several data will be requested like:'
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 <Blueprint> on <Provider> as <InstanceName> [options] # Boot a new forge with the following options'
46
- puts ' where:'
47
- puts ' blueprint : Is the name of the blueprint (currently cli only supports redstone)'
48
- puts ' Provider : in which cloud provider to deploy the forge'
49
- puts ' InstanceName : name of the forge'
50
- puts ''
51
- puts ' Ex: forj boot redstone on hpcloud as maestro_test'
52
- puts ''
53
- puts ' [Options] are:'
54
- puts ' -b build: replace the default build.sh'
55
- puts ' -bcd build_config_dir: defines the build configuration directory to load the build configuration file'
56
- puts ' -bc build_config: the build config file to load <confdir>/<BoxName>.<Config>.env.'
57
- puts ' -gb branch: the build will extract from git branch name'
58
- puts ' -tb test_box (not yet implemented): create test-box meta from the repository path provided.'
59
- puts ' -gr git_repo: the box built will use a different git repository sent out to <user_data>'
60
- puts ' -bh boothook: by default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.'
61
- puts ' -bn box_name: defines the name of the box or box image to build.'
62
- puts ''
63
- puts ' forj ssh <Name> <Node> # Connect through ssh to an existing instance'
64
- puts ' where'
65
- puts ' InstanceName: is the name of the forge (maestro_test)'
66
- puts ' Node : is the name of the node (maestro, ci, etc...)'
67
- puts ''
68
- puts ' forj down <InstanceName> # Delete a forge and create a backup of your data'
69
- puts ' not yet implemented'
70
- puts ''
71
- puts ' forj help # Display this help'
72
- end
73
40
 
74
- desc 'boot', 'boot a Maestro box and instruct it to provision the blueprint'
75
41
 
76
- method_option :build, :aliases => '-u', :desc => 'Replace the default build.sh'
77
- method_option :infra, :aliases => '-I', :desc => 'Defines the Infra directory to load the build configuration file. You can set FORJ_INFRA_DIR. By default, it will look in your current directory.'
78
- method_option :build_config, :aliases => '-c', :desc => 'The build config file to load <confdir>/<BoxName>.<Config>.env. By default, uses "master" as Config.'
79
- method_option :branch, :aliases => '-b', :desc => 'The build will extract from git branch name. It sets the configuration build <config> to the branch name <branch>.'
80
- method_option :test_box, :aliases => '-t', :desc => 'Create test.rb-box meta from the repository path provided.'
81
- method_option :git_repo, :aliases => '-r', :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.'
82
- method_option :boothook, :aliases => '-h', :desc => 'By default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.'
83
- method_option :box_name, :aliases => '-x', :desc => 'Defines the name of the box or box image to build.'
42
+ desc "help [action]", "Describe available FORJ actions or one specific action"
43
+ def help(task = nil, subcommand = false)
44
+ if task
45
+ self.class.task_help(shell, task)
46
+ else
47
+ puts <<-LONGDESC
48
+ Quick steps: How to create a forj?
49
+ ----------------------------------
50
+
51
+ 1. Setup your first forj account.
52
+ `$ forj setup [Provider]`
53
+
54
+ Ex: `forj setup hpcloud`. In this example, your account will be named 'hpcloud'.
55
+
56
+ IMPORTANT NOTE: Without any provider, forj setup will choose 'hpcloud' as provider.
57
+ Currently, forj supports only hpcloud. Openstack will be available soon.
58
+
59
+ 2. Create your forge on your default account
60
+ `$ forj boot <blueprint> on <Provider> as <InstanceName> `
61
+
62
+ Ex: `forj boot redstone on hpcloud as MyForge`
63
+
64
+ forj command line details:
65
+ --------------------------
66
+ LONGDESC
67
+ self.class.help(shell, subcommand)
68
+ end
69
+ end
70
+
71
+ # BOOT
72
+ desc 'boot <Blueprint> on <Provider> as <InstanceName> [options]', 'boot a Maestro box and instruct it to provision the blueprint'
73
+
74
+ long_desc <<-LONGDESC
75
+ This task boot a new forge with the following options
76
+ \x5- blueprint : Is the name of the blueprint (currently cli only supports redstone)
77
+ \x5- Provider : in which cloud provider to deploy the forge
78
+ \x5- InstanceName : name of the forge
79
+
80
+ Ex: forj boot redstone on hpcloud as maestro_test
81
+
82
+ `forj boot` load predefine valued from `lib/defaults.yaml`. If you need to change one of them, add this value in your ~/.forj/config.yaml.
83
+ The list of predefined values can be retrieved with forj show defaults
84
+
85
+ LONGDESC
86
+
87
+ method_option :config, :aliases => '-c', :desc => 'Path to a different forj config file. By default, use ~/.forj/config.yaml'
88
+ method_option :infra, :aliases => '-i', :desc => 'Defines your Infra directory to use while booting. You can also set FORJ_INFRA_DIR.'
84
89
  method_option :key_name, :aliases => '-k', :desc => 'Import a key pair.'
85
90
  method_option :key_path, :aliases => '-p', :desc => 'Public key data'
86
- method_option :catalog, :aliases => '-y', :desc => 'A path for the yaml file data about the blueprint'
87
91
 
92
+ method_option :boothook, :aliases => '-H', :desc => 'By default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.'
93
+ method_option :build, :aliases => '-B', :desc => 'Replace the default build.sh'
94
+ method_option :build_config, :aliases => '-C', :desc => 'The build config file to load <confdir>/<BoxName>.<Config>.env. By default, uses "master" as Config.'
95
+ method_option :git_repo, :aliases => '-R', :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.'
96
+ method_option :branch, :aliases => '-B', :desc => 'The build will extract from git branch name. It sets the configuration build <config> to the branch name <branch>.'
97
+ method_option :box_name, :aliases => '-N', :desc => 'Defines the name of the box or box image to build.'
98
+ method_option :test_box, :aliases => '-T', :desc => 'Create test.rb-box meta from the repository path provided.'
99
+
88
100
  def boot(blueprint, on, cloud_provider, as, name, test = false)
89
101
  Boot.boot(blueprint, cloud_provider, name,
90
102
  options[:build], options[:build_config_dir],
@@ -92,20 +104,54 @@ class Forj < Thor
92
104
  options[:git_repo], options[:boothook],
93
105
  options[:box_name], options[:key_name],
94
106
  options[:key_path],options[:region],
95
- options[:catalog], test)
107
+ options[:config], test)
96
108
  end
97
109
 
110
+ desc 'show defaults', 'Show list of predefined value you can update in your ~/.forj/config.yaml'
111
+
112
+ def show(name)
113
+ oConfig=ForjConfig.new()
114
+
115
+ puts 'List of predefined values:
116
+ --------------------------'
117
+ puts oConfig.yDefaults['default'].to_yaml()
118
+ puts '--------------------------'
119
+ puts "You can set any of those variable in your ~/.forj/config.yaml, under section 'default:'"
120
+ end
121
+ # DOWN
98
122
  desc 'down', 'delete the Maestro box and all systems installed by the blueprint'
123
+ long_desc <<-LONGDESC
124
+ Not yet implemented
125
+ LONGDESC
126
+
99
127
  def down(name)
100
128
  Down.down(name)
101
129
  end
102
130
 
131
+ # SSH
103
132
  desc 'ssh', 'connect to your forge thru ssh'
133
+ long_desc <<-LONGDESC
134
+ Connect through ssh to an existing instance
135
+
136
+ not yet implemented
137
+ LONGDESC
138
+
104
139
  def ssh(name, server)
105
140
  Ssh.connect(name, server)
106
141
  end
107
142
 
143
+ # SETUP
108
144
  desc 'setup', 'set the credentials for forj cli'
145
+ long_desc <<-LONGDESC
146
+ Set the cloud credentials and services for forj. Currently supports only hpcloud provider.
147
+
148
+ Several data will be requested like:
149
+ \x5- access_key: access key from hpcloud
150
+ \x5- secret_key: secret key from hpcloud
151
+ \x5- auth_uri: identity endpoint
152
+ \x5- tenant_id: id for the tenant you want to use
153
+ \x5- availability_zone: which availability zone will be deployed
154
+ LONGDESC
109
155
  def setup
110
156
  Setup.setup
111
157
  end
data/lib/boot.rb CHANGED
@@ -16,8 +16,6 @@
16
16
  # limitations under the License.
17
17
 
18
18
 
19
-
20
-
21
19
  require_relative 'network.rb'
22
20
  include Network
23
21
  require_relative 'yaml_parse.rb'
@@ -31,6 +29,7 @@ include Logging
31
29
  require_relative 'helpers.rb'
32
30
  include Helpers
33
31
 
32
+
34
33
  #
35
34
  # Boot module
36
35
  #
@@ -38,28 +37,24 @@ module Boot
38
37
  def boot(blueprint, cloud_provider, name,
39
38
  build, infra_dir, build_config,
40
39
  branch, git_repo, boothook, box_name,
41
- key_name, key_path, region, catalog,
40
+ key_name, key_path, region, config,
42
41
  test = false)
43
42
  begin
44
43
  initial_msg = 'booting %s on %s (~/.forj/forj.log)' % [blueprint , cloud_provider]
45
44
 
46
45
  Logging.info(initial_msg)
47
- puts ('INFO: Reading default configuration...')
48
46
 
49
47
  forj_dir = File.expand_path(File.dirname(__FILE__))
50
48
  Dir.chdir(forj_dir)
51
49
 
52
- #TODO: Consider defaults.yaml as default variables, and load more from ~/.forj/forj-config.yaml, to change defaults on user need.
53
- if catalog
54
- definitions = YamlParse.get_values(catalog)
55
- else
56
- definitions = YamlParse.get_values('defaults.yaml')
57
- end
58
-
50
+ puts ('INFO: Reading default configuration...')
51
+ oConfig=ForjConfig.new(config)
52
+ hConfig=oConfig.yConfig['default']
53
+
59
54
  # Initialize defaults
60
- maestro_url = definitions['default']['maestro_url']
55
+ maestro_url = hConfig['maestro_url']
61
56
 
62
- infra_dir = definitions['default']['infra_repo'] unless infra_dir
57
+ infra_dir = hConfig['infra_repo'] unless infra_dir
63
58
 
64
59
  # Ask information if needed.
65
60
  bBuildInfra=false
@@ -77,31 +72,31 @@ module Boot
77
72
  # Step Maestro Clone
78
73
  puts('INFO: cloning maestro repo from \'%s\'...' % maestro_url)
79
74
  Repositories.clone_repo(maestro_url)
80
-
75
+
81
76
  if bBuildInfra
82
77
  puts('INFO: Building your infra... in \'%s\'' % [infra_dir])
83
78
  Repositories.create_infra
84
79
  end
85
80
 
86
- puts('INFO: Configuring network \'%s\'' % [definitions['default']['network']])
87
- network = Network.get_or_create_network(definitions['default']['network'])
81
+ puts('INFO: Configuring network \'%s\'' % [hConfig['network']])
82
+ network = Network.get_or_create_network(hConfig['network'])
88
83
  begin
89
84
  subnet = Network.get_or_create_subnet(network.id, name)
90
- router = Network.get_router(definitions['default']['router'])
85
+ router = Network.get_router(hConfig['router'])
91
86
  Network.create_router_interface(subnet.id, router)
92
87
  rescue => e
93
88
  puts e.message
94
89
  end
95
90
 
96
91
 
97
- puts('INFO: Configuring keypair \'%s\'' % [definitions['default']['keypair_name']])
98
- key_name = definitions['default']['keypair_name'] unless key_name
99
- key_path = definitions['default']['keypair_path'] unless key_path
92
+ puts('INFO: Configuring keypair \'%s\'' % [hConfig['keypair_name']])
93
+ key_name = hConfig['keypair_name'] unless key_name
94
+ key_path = hConfig['keypair_path'] unless key_path
100
95
  SecurityGroup.upload_existing_key(key_name, key_path)
101
96
 
102
- puts('INFO: Configuring Security Group \'%s\'' % [definitions['default']['security_group']])
103
- security_group = SecurityGroup.get_or_create_security_group(definitions['default']['security_group'])
104
- ports = definitions['default']['ports']
97
+ puts('INFO: Configuring Security Group \'%s\'' % [hConfig['security_group']])
98
+ security_group = SecurityGroup.get_or_create_security_group(hConfig['security_group'])
99
+ ports = hConfig['ports']
105
100
 
106
101
  ports.each do|port|
107
102
  Network.get_or_create_rule(security_group.id, 'tcp', port, port)
@@ -124,19 +119,19 @@ module Boot
124
119
 
125
120
  build = 'bin/build.sh' unless build
126
121
 
127
- build_config = definitions['default']['build_config'] unless build_config
122
+ build_config = hConfig['build_config'] unless build_config
128
123
 
129
- branch = definitions['default']['branch'] unless branch
124
+ branch = hConfig['branch'] unless branch
130
125
 
131
- box_name = definitions['default']['box_name'] unless box_name
126
+ box_name = hConfig['box_name'] unless box_name
132
127
 
133
- meta = '--meta blueprint=%s --meta HPCLOUD_PRIV=~/.cache/forj/master.forj-13.5.g64' % [blueprint]
128
+ meta = '--meta blueprint=%s ' % [blueprint]
134
129
 
135
130
  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, meta]
136
131
 
137
132
  Logging.info('Calling build.sh')
138
133
  Logging.info(command)
139
-
134
+
140
135
  Kernel.system(command)
141
136
  Dir.chdir(current_dir)
142
137
 
data/lib/defaults.yaml CHANGED
@@ -24,7 +24,6 @@ default:
24
24
  security_group: default
25
25
  network: private
26
26
  # at this point you have to clone the infra project manually
27
- build_config_dir: ~/forj/infra/build/boxes/maestro
28
27
  build_config: box
29
28
  branch: master
30
29
  box_name: maestro
@@ -0,0 +1,163 @@
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
+ # puts "test_library included"
20
+
21
+ require 'rubygems'
22
+ require 'yaml'
23
+
24
+ require_relative 'log.rb'
25
+ include Logging
26
+
27
+ class ForjDefault
28
+
29
+ # @sDefaultsName='defaults.yaml'
30
+ # @yDefaults = defaults.yaml file data hash
31
+
32
+ attr_reader :yDefaults
33
+
34
+ def initialize()
35
+ # Load yaml documents (defaults)
36
+ # If config doesn't exist, it will be created, empty with 'defaults:' only
37
+
38
+ if not $LIB_PATH
39
+ raise 'Internal $LIB_PATH was not set.'
40
+ end
41
+
42
+ @sDefaultsName=File.join($LIB_PATH,'defaults.yaml')
43
+
44
+ @yDefaults=YAML.load_file(@sDefaultsName)
45
+ end
46
+
47
+ end
48
+
49
+ class ForjConfig
50
+
51
+ # Internal variables:
52
+ # @sConfigName='config.yaml'
53
+ # @yLocal = config.yaml file data hash.
54
+ # @yConfig = defaults.yaml + local_config data hash
55
+
56
+
57
+ attr_reader :yLocal
58
+ attr_reader :yConfig
59
+ attr_reader :sConfigName
60
+
61
+ def initialize(sConfigName=nil)
62
+ # Load yaml documents (defaults + config)
63
+ # If config doesn't exist, it will be created, empty with 'defaults:' only
64
+
65
+
66
+ if not $FORJ_DATA_PATH
67
+ raise 'Internal $FORJ_DATA_PATH was not set.'
68
+ end
69
+
70
+ sConfigDefaultName='config.yaml'
71
+
72
+ # binding.pry
73
+ if sConfigName
74
+ if File.dirname(sConfigName) == '.'
75
+ sConfigName= File.join($FORJ_DATA_PATH,sConfigName)
76
+ end
77
+ sConfigName = File.expand_path(sConfigName)
78
+ if not File.exists?(sConfigName)
79
+ Logging.error('Config file %s doesn\'t exists. Using default one.')
80
+ @sConfigName=File.join($FORJ_DATA_PATH,sConfigDefaultName)
81
+ else
82
+ @sConfigName=sConfigName
83
+ end
84
+ else
85
+ @sConfigName=File.join($FORJ_DATA_PATH,sConfigDefaultName)
86
+ end
87
+
88
+
89
+ @Default=ForjDefault.new
90
+
91
+
92
+ if File.exists?(@sConfigName)
93
+ @yLocal=YAML.load_file(@sConfigName)
94
+ else
95
+ @yLocal={ 'default' => nil }
96
+ if not File.exists?(@sConfigName)
97
+ # Write the empty file
98
+ if not File.exists?($FORJ_DATA_PATH)
99
+ Dir.mkdir($FORJ_DATA_PATH)
100
+ end
101
+ puts ('INFO: Creating your default configuration file ...')
102
+ self.SaveConfig()
103
+ end
104
+ end
105
+
106
+ BuildConfig()
107
+ end
108
+
109
+
110
+ def SaveConfig()
111
+ begin
112
+ File.open(@sConfigName, 'w') do |out|
113
+ YAML.dump(@yLocal, out)
114
+ end
115
+ rescue => e
116
+ Logging.error(e.message)
117
+ return false
118
+ end
119
+ # puts ('INFO: Configuration file "%s" updated.' % @sConfigName)
120
+ return true
121
+ end
122
+
123
+ def ConfigSet(key, value, section = 'default')
124
+ if not key or not value
125
+ return false
126
+ end
127
+ if @yLocal[section] == nil
128
+ @yLocal[section]={}
129
+ end
130
+ if @yLocal.has_key?(section)
131
+ @yLocal[section].merge!({key => value})
132
+ else
133
+ @yLocal.merge!(section => {key => value})
134
+ end
135
+ BuildConfig()
136
+ return true
137
+ end
138
+
139
+ def ConfigDel(key,section = 'default')
140
+ if not key
141
+ return false
142
+ end
143
+ if not @yLocal.has_key?(section)
144
+ return false
145
+ end
146
+ @yLocal[section].delete(key)
147
+ BuildConfig()
148
+ return true
149
+ end
150
+
151
+
152
+ def BuildConfig()
153
+ # This function implements the logic to get defaults, superseed by local config.
154
+ # Take care of ports array, which is simply merged.
155
+
156
+ @yConfig={ 'default' => @Default.yDefaults['default'].clone }
157
+ if @yLocal['default']
158
+ @yConfig['default'].merge!(@yLocal['default']) { |key, oldval, newval| key == 'ports'? newval.clone.push(oldval.clone).flatten: newval }
159
+ end
160
+ @yConfig.merge!(@yLocal) { |key, oldval, newval| key == 'default'? oldval: newval }
161
+ end
162
+
163
+ end
data/lib/setup.rb CHANGED
@@ -21,6 +21,8 @@ require 'highline/import'
21
21
 
22
22
  require_relative 'yaml_parse.rb'
23
23
  include YamlParse
24
+ require_relative 'helpers.rb'
25
+ include Helpers
24
26
 
25
27
  #
26
28
  # Setup module call the hpcloud functions
@@ -40,6 +42,7 @@ def setup_credentials
40
42
  hpcloud_os_key = ask('Enter hpcloud password: ') { |q| q.echo = '*'}
41
43
 
42
44
  home = File.expand_path('~')
45
+ Helpers.create_directory('%s/.cache/forj/' % [home])
43
46
  creds = '%s/.cache/forj/creds' % [home]
44
47
 
45
48
  values = {:credentials => {:hpcloud_os_user=> hpcloud_os_user, :hpcloud_os_key=> hpcloud_os_key}}
@@ -67,12 +70,9 @@ def save_cloud_fog
67
70
  os_key = local_template[:credentials][:hpcloud_os_key]
68
71
 
69
72
  File.open(cloud_fog, 'w') {|file|
70
- file.write('HPCLOUD_OS_USER=%s' % [os_user])
71
- file.write("\n")
72
- file.write('HPCLOUD_OS_KEY=%s' % [os_key])
73
- file.write("\n")
74
- file.write('DNS_KEY=%s' % [access_key])
75
- file.write("\n")
73
+ file.write('HPCLOUD_OS_USER=%s' % [os_user] + "\n")
74
+ file.write('HPCLOUD_OS_KEY=%s' % [os_key] + "\n")
75
+ file.write('DNS_KEY=%s' % [access_key] + "\n")
76
76
  file.write('DNS_SECRET=%s' % [secret_key])
77
77
  }
78
78
 
@@ -0,0 +1,112 @@
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
+ class TestClass
19
+ end
20
+
21
+ require_relative '../lib/forj-config.rb'
22
+ $APP_PATH = File.dirname(__FILE__)
23
+ $LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
24
+ $FORJ_DATA_PATH= File.expand_path('~/.forj')
25
+
26
+ describe 'forj cli' do
27
+ describe ".forj-config" do
28
+ context "new instance" do
29
+
30
+ it 'should be loaded' do
31
+ @test_config=ForjConfig.new()
32
+ expect(@test_config).to be
33
+ end
34
+
35
+ end
36
+
37
+ context "Config in memory" do
38
+ before(:all) do
39
+ @config=ForjConfig.new()
40
+ end
41
+
42
+ it 'should be able to create a key/value in local config' do
43
+ @config.ConfigSet('test1','value')
44
+ @config.yConfig['default']['test1'].should == 'value'
45
+ end
46
+
47
+ it 'should be able to remove the previously created key/value from local config' do
48
+ @config.ConfigDel('test1')
49
+ @config.yConfig['default'].key?('test1').should == false
50
+ end
51
+ end
52
+
53
+
54
+ context "Updating local config file" do
55
+ before(:all) do
56
+ @config=ForjConfig.new()
57
+ end
58
+
59
+ after(:all) do
60
+ @config.ConfigDel('test1')
61
+ @config.SaveConfig()
62
+ end
63
+
64
+ it 'should save a key/value in local config' do
65
+ @config.ConfigSet('test1','value')
66
+ @config.SaveConfig().should == true
67
+ end
68
+
69
+ it 'should get the saved value from local config' do
70
+ oConfig=ForjConfig.new()
71
+ @config.yConfig['default']['test1'].should == 'value'
72
+ end
73
+
74
+ end
75
+
76
+ context "Updating another config file from .forj" do
77
+
78
+ before(:all) do
79
+ if File.exists?('~/.forj/test.yaml')
80
+ File.delete(File.expand_path('~/.forj/test.yaml'))
81
+ end
82
+ File.open(File.expand_path('~/.forj/test1.yaml'), 'w+') { |file| file.write("default:\n") }
83
+ @config=ForjConfig.new('test.yaml')
84
+ @config2=ForjConfig.new('test1.yaml')
85
+ end
86
+
87
+ after(:all) do
88
+ File.delete(File.expand_path('~/.forj/test1.yaml'))
89
+ end
90
+
91
+ it 'If file do not exist, warning! and file is not created.' do
92
+ File.exists?(File.expand_path('~/.forj/test.yaml')).should == false
93
+ end
94
+
95
+ it 'Then, default config is loaded.' do
96
+ File.basename(@config.sConfigName).should == 'config.yaml'
97
+ end
98
+
99
+ it 'test1.yaml config is loaded.' do
100
+ File.basename(@config2.sConfigName).should == 'test1.yaml'
101
+ end
102
+
103
+ it 'should save a key/value in test2 config' do
104
+ @config2.ConfigSet('test2','value')
105
+ @config2.SaveConfig().should == true
106
+ end
107
+
108
+
109
+ end
110
+ end
111
+
112
+ end
@@ -27,11 +27,11 @@ class TestClass
27
27
  end
28
28
 
29
29
  describe 'repositories' do
30
- it 'its clonning the repo' do
30
+ it 'should clone the repo' do
31
31
  @test_class = TestClass.new
32
32
  @test_class.extend(Repositories)
33
33
 
34
- repo = @test_class.clone_repo
34
+ repo = @test_class.clone_repo('https://github.com/forj-oss/maestro')
35
35
  expect(repo).to be
36
36
  end
37
- end
37
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
5
- prerelease:
4
+ version: 0.0.34
6
5
  platform: ruby
7
6
  authors:
8
7
  - forj team
@@ -13,81 +12,102 @@ date: 2014-06-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
- requirement: &16777300 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.16.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *16777300
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.0
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: nokogiri
27
- requirement: &16776760 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: 1.5.11
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *16776760
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.11
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: fog
38
- requirement: &16776080 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: 1.19.0
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *16776080
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.19.0
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: hpcloud
49
- requirement: &16775160 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: 2.0.8
55
62
  type: :runtime
56
63
  prerelease: false
57
- version_requirements: *16775160
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.8
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: git
60
- requirement: &16773180 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
- - - ! '>='
73
+ - - '>='
64
74
  - !ruby/object:Gem::Version
65
75
  version: 1.2.7
66
76
  type: :runtime
67
77
  prerelease: false
68
- version_requirements: *16773180
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.7
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rbx-require-relative
71
- requirement: &16771380 !ruby/object:Gem::Requirement
72
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
73
86
  requirements:
74
87
  - - ~>
75
88
  - !ruby/object:Gem::Version
76
89
  version: 0.0.7
77
90
  type: :runtime
78
91
  prerelease: false
79
- version_requirements: *16771380
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.0.7
80
97
  - !ruby/object:Gem::Dependency
81
98
  name: highline
82
- requirement: &16786340 !ruby/object:Gem::Requirement
83
- none: false
99
+ requirement: !ruby/object:Gem::Requirement
84
100
  requirements:
85
101
  - - ~>
86
102
  - !ruby/object:Gem::Version
87
103
  version: 1.6.21
88
104
  type: :runtime
89
105
  prerelease: false
90
- version_requirements: *16786340
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.6.21
91
111
  description: forj command line
92
112
  email:
93
113
  - forj@forj.io
@@ -112,6 +132,7 @@ files:
112
132
  - lib/log.rb
113
133
  - lib/helpers.rb
114
134
  - lib/build_tmpl/build-env.py
135
+ - lib/forj-config.rb
115
136
  - spec/boot_spec.rb
116
137
  - spec/connection_spec.rb
117
138
  - spec/down_spec.rb
@@ -121,32 +142,32 @@ files:
121
142
  - spec/spec_helper.rb
122
143
  - spec/ssh_spec.rb
123
144
  - spec/yaml_parse_spec.rb
145
+ - spec/forj-config_spec.rb
124
146
  - Rakefile
125
147
  - Gemfile
126
148
  - README.md
127
149
  homepage: https://forj.io
128
150
  licenses:
129
151
  - Apache License, Version 2.0.
152
+ metadata: {}
130
153
  post_install_message: Go to docs.forj.io for more information on how to use forj cli
131
154
  rdoc_options: []
132
155
  require_paths:
133
156
  - lib
134
157
  required_ruby_version: !ruby/object:Gem::Requirement
135
- none: false
136
158
  requirements:
137
- - - ! '>='
159
+ - - '>='
138
160
  - !ruby/object:Gem::Version
139
161
  version: 1.8.5
140
162
  required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
163
  requirements:
143
- - - ! '>='
164
+ - - '>='
144
165
  - !ruby/object:Gem::Version
145
166
  version: '0'
146
167
  requirements: []
147
168
  rubyforge_project:
148
- rubygems_version: 1.8.11
169
+ rubygems_version: 2.1.11
149
170
  signing_key:
150
- specification_version: 3
171
+ specification_version: 4
151
172
  summary: forj command line
152
173
  test_files: []