forj 1.0.10 → 1.0.11

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.
@@ -0,0 +1,61 @@
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
+ :default:
16
+ :maestro_url: https://github.com/forj-oss/maestro.git
17
+
18
+ # Default Infra repository to use. If missing, it will be proposed to be created.
19
+ :infra_repo: ~/.forj/infra
20
+
21
+ # You can set proto2b in your ~/.forj/config.yaml if you built it from maestro/build. Read the maestro/README.md to create it.
22
+ :image_name: Ubuntu Precise 12.04.4 LTS Server 64-bit 20140414 (Rescue Image)
23
+
24
+ # Flavor to use for Maestro
25
+ :flavor: medium
26
+ # Default flavor to use for all Blueprint nodes.
27
+ :bp_flavor: small
28
+
29
+ # Ports to open for Maestro, added to the security group
30
+ :security_group: forj
31
+ :ports: [22, 80, 443, 3000, 3131-3135, 4505-4506, 5000, 5666, 8000, 8080-8081, 8083, 8125, 8139-8140, 8773-8776, 9292, 29418, 35357]
32
+
33
+ # Network: If network doesn't exist, forj cli will try to create it, and attach it a router.
34
+ :network: forj
35
+
36
+ # Users: Default user for ssh connection, if user doesn't exits, forj cli will try to get the user from the server image on it's name attribute
37
+ :users: ['ubuntu', 'fedora', 'cloud-user', 'cirros', 'centos', 'cloud', 'root']
38
+
39
+ # build.sh internal variables.
40
+ :build_config: box
41
+ :branch: master
42
+ :box_name: maestro
43
+
44
+ :provider_name: hpcloud
45
+
46
+ :maestro_bootstrap_dir: build/maestro/bootstrap
47
+ :description:
48
+ # Description of build.sh environment variable defined by forj cli for build.sh. (~/.forj/infra/build/<Account>.build.env)
49
+ :FORJ_HPC: "HPCloud cli Account used to build your Maestro box"
50
+ :FORJ_HPC_COMPUTE: "HPCloud Compute service (like region-b.geo-1) used to run your Maestro Box"
51
+ :FORJ_TENANT_NAME: "HPCloud Tenant name used build your <Blueprint> nodes"
52
+ :FORJ_HPC_NET: "HPCloud Network name to use, while booting all boxes."
53
+ :FORJ_KEYPAIR: "Keypair used to access boxes."
54
+ :FORJ_SECURITY_GROUP: "Security group associated to each box"
55
+ :FORJ_HPC_NOVA_KEYPUB: "Public key used by build.sh to ensure his existence on HPCloud"
56
+ :FORJ_BASE_IMG: "Base image used to build all boxes"
57
+ :FORJ_FLAVOR: "Flavor used to build Maestro"
58
+ # DNS specific data
59
+ :FORJ_DNS_TENANTID: "HPCloud Project ID to use to create DNS entries for each boxes."
60
+ :FORJ_DNS_ZONE: "HPCloud Domain name service to use for each boxes DNS entries. (Ex: region-a.geo-1)"
61
+ :FORJ_DNS_DOMAIN: "Domain used for DNS. Each server will be attached to a public IP. An 'A' record in the DNS service will need to be added to your HPCloud DOMAIN."
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
 
4
3
  # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
@@ -15,16 +14,12 @@
15
14
  # See the License for the specific language governing permissions and
16
15
  # limitations under the License.
17
16
 
18
- FORJCORE_PATH = File.expand_path(File.dirname(__FILE__))
19
-
20
- require File.join(FORJCORE_PATH, 'process', 'ForjProcess.rb')
21
-
22
17
  # Defines how to manage Maestro and forges
23
18
  # create a maestro box. Identify a forge instance, delete it,...
24
19
 
25
20
  # Define framework object on BaseDefinition
26
21
  # See lib/core/definition.rb for function details usage.
27
- class Lorj::BaseDefinition
22
+ class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
28
23
  process_default :use_controller => false
29
24
 
30
25
  # ******************* Maestro Repository object
@@ -52,26 +47,28 @@ class Lorj::BaseDefinition
52
47
  :create_e => :build_metadata
53
48
 
54
49
  obj_needs :data, :instance_name
55
- obj_needs :data, :network_name
56
- obj_needs :data, :security_group
57
- obj_needs :data, :keypair_name
58
- obj_needs :data, :image_name
59
- obj_needs :data, :bp_flavor
60
- obj_needs :data, :compute
61
- obj_needs :data, :branch
62
- obj_needs :data, :domain_name
63
- obj_needs :data, :tenant_name
50
+ obj_needs :data, 'maestro#network_name'
51
+ obj_needs :data, 'maestro#security_group'
52
+ obj_needs :data, 'credentials#keypair_name'
53
+ obj_needs :data, 'maestro#image_name'
54
+ obj_needs :data, 'maestro#bp_flavor'
55
+ obj_needs :data, 'services#compute'
56
+ obj_needs :data, 'maestro#branch'
57
+ obj_needs :data, 'dns#domain_name'
58
+ obj_needs :data, 'maestro#tenant_name'
64
59
  # sent in base64
65
- obj_needs :data, :os_user
66
- obj_needs :data, :os_enckey
67
- obj_needs :data, :account_id
68
- obj_needs :data, :account_key
69
- obj_needs :data, :auth_uri
60
+ obj_needs :data, 'credentials#os_user'
61
+ obj_needs :data, 'credentials#os_enckey'
62
+ obj_needs :data, 'credentials#account_id'
63
+ obj_needs :data, 'credentials#account_key'
64
+ obj_needs :data, 'credentials#auth_uri'
70
65
  obj_needs_optional
71
66
 
72
67
  # If requested by user, ask Maestro to manage the DNS.
73
- obj_needs :data, :dns_service
74
- obj_needs :data, :dns_tenant_id
68
+ obj_needs :data, 'dns#dns_service'
69
+ obj_needs :data, 'dns#dns_tenant_id'
70
+ obj_needs :data, :test_box
71
+ obj_needs :data, :test_box_path
75
72
 
76
73
  # If requested by user, ask Maestro to instantiate a blueprint.
77
74
  obj_needs :data, :blueprint
@@ -93,20 +90,46 @@ class Lorj::BaseDefinition
93
90
 
94
91
  # ******************* forge object
95
92
  define_obj :forge,
96
-
97
93
  :create_e => :build_forge,
98
94
  :delete_e => :delete_forge,
99
95
  :get_e => :get_forge
100
96
 
101
- obj_needs :CloudObject, :compute_connection
102
- obj_needs :CloudObject, :metadata, :for => [:create_e]
103
- obj_needs :CloudObject, :userdata, :for => [:create_e]
104
- obj_needs :data, :instance_name, :for => [:create_e]
97
+ obj_needs :CloudObject, :compute_connection
98
+ obj_needs :CloudObject, :metadata, :for => [:create_e]
99
+ obj_needs :CloudObject, :userdata, :for => [:create_e]
100
+ obj_needs :data, :instance_name, :for => [:create_e]
101
+ obj_needs :data, 'maestro#image_name', :for => [:create_e]
102
+ obj_needs :data, 'maestro#flavor_name', :for => [:create_e]
103
+ obj_needs :data, 'maestro#network_name', :for => [:create_e]
104
+ obj_needs :data, 'maestro#security_group', :for => [:create_e]
105
105
 
106
106
  obj_needs_optional
107
107
  obj_needs :CloudObject, :server
108
+ obj_needs :CloudObject, :image, :for => [:create_e]
108
109
  obj_needs :CloudObject, :public_ip, :for => [:create_e]
109
110
  obj_needs :CloudObject, :keypairs, :for => [:create_e]
110
111
  obj_needs :data, :blueprint
111
112
  obj_needs :data, :forge_server, :for => [:delete_e]
113
+
114
+ # Adding support of test-box script
115
+ obj_needs :data, :test_box, :for => [:create_e]
116
+ obj_needs :data, :test_box_path, :for => [:create_e]
117
+ # Defines how cli will control FORJ features
118
+ # boot/down/ssh/...
119
+
120
+ # Define framework object on BaseDefinition
121
+ # See lib/core/definition.rb for function details usage.
122
+ # ************************************ SSH Object
123
+ define_obj(:ssh,
124
+
125
+ :create_e => :ssh_connection
126
+ )
127
+ obj_needs :CloudObject, :forge
128
+ obj_needs :data, :instance_name
129
+ obj_needs :data, 'credentials#keypair_name'
130
+ obj_needs :data, :keypair_path
131
+
132
+ obj_needs_optional
133
+ obj_needs :data, :forge_server
134
+ obj_needs :data, :ssh_user
112
135
  end
@@ -69,7 +69,11 @@ class ForjCoreProcess
69
69
  o_forge = process_get(sObjectType, config[:instance_name])
70
70
  if o_forge.empty? || o_forge[:servers].length == 0
71
71
  PrcLib.high_level_msg("\nBuilding your forge...\n")
72
- process_create(:internet_server)
72
+ process_create(:internet_server,
73
+ :image_name => hParams['maestro#image_name'],
74
+ :flavor_name => hParams['maestro#flavor_name'],
75
+ :network_name => hParams['maestro#network_name'],
76
+ :security_group => hParams['maestro#security_group'])
73
77
  o_forge[:servers, 'maestro'] = hParams.refresh[:server]
74
78
  else
75
79
  o_forge = load_existing_forge(o_forge, hParams)
@@ -291,6 +295,9 @@ class ForjCoreProcess
291
295
  m_cloud_init_error = output_options[:error]
292
296
  o_old_log = output_options[:old_log]
293
297
  i_cur_act = output_options[:cur_act]
298
+
299
+ tb_detect(hParams, o_old_log)
300
+
294
301
  if pending_count == 60
295
302
  image = server_get_image o_server
296
303
  highlight = ANSI.yellow('-' * 40)
@@ -560,10 +567,10 @@ class ForjCoreProcess
560
567
  def load_hpcloud(hParams, os_key)
561
568
  hpcloud_priv = nil
562
569
  IO.popen('gzip -c', 'r+') do|pipe|
563
- pipe.puts(format('HPCLOUD_OS_USER=%s', hParams[:os_user]))
570
+ pipe.puts(format('HPCLOUD_OS_USER=%s', hParams['credentials#os_user']))
564
571
  pipe.puts(format('HPCLOUD_OS_KEY=%s', os_key))
565
- pipe.puts(format('DNS_KEY=%s', hParams[:account_id]))
566
- pipe.puts(format('DNS_SECRET=%s', hParams[:account_key]))
572
+ pipe.puts(format('DNS_KEY=%s', hParams[:'credentials#account_id']))
573
+ pipe.puts(format('DNS_SECRET=%s', hParams['credentials#account_key']))
567
574
  pipe.close_write
568
575
  hpcloud_priv = pipe.read
569
576
  end
@@ -572,29 +579,29 @@ class ForjCoreProcess
572
579
 
573
580
  def load_h_meta(hParams, hpcloud_priv)
574
581
  h_meta = {
575
- 'flavor_name' => hParams[:bp_flavor],
582
+ 'flavor_name' => hParams['maestro#bp_flavor'],
576
583
  'cdksite' => config.get(:server_name),
577
- 'cdkdomain' => hParams[:domain_name],
584
+ 'cdkdomain' => hParams['dns#domain_name'],
578
585
  'eroip' => '127.0.0.1',
579
586
  'erosite' => config.get(:server_name),
580
- 'erodomain' => hParams[:domain_name],
581
- 'gitbranch' => hParams[:branch],
582
- 'security_groups' => hParams[:security_group],
583
- 'tenant_name' => hParams[:tenant_name],
584
- 'network_name' => hParams[:network_name],
585
- 'hpcloud_os_region' => hParams[:compute],
587
+ 'erodomain' => hParams['dns#domain_name'],
588
+ 'gitbranch' => hParams['maestro#branch'],
589
+ 'security_groups' => hParams['maestro#security_group'],
590
+ 'tenant_name' => hParams['maestro#tenant_name'],
591
+ 'network_name' => hParams['maestro#network_name'],
592
+ 'hpcloud_os_region' => hParams['services#compute'],
586
593
  'PUPPET_DEBUG' => 'True',
587
- 'image_name' => hParams[:image_name],
588
- 'key_name' => hParams[:keypair_name],
594
+ 'image_name' => hParams['maestro#image_name'],
595
+ 'key_name' => hParams['credentials#keypair_name'],
589
596
  # Remove pad
590
597
  'hpcloud_priv' => Base64.strict_encode64(hpcloud_priv).gsub('=', ''),
591
- 'compute_os_auth_url' => hParams[:auth_uri]
598
+ 'compute_os_auth_url' => hParams['credentials#auth_uri']
592
599
  }
593
600
 
594
- if hParams[:dns_service]
595
- h_meta['dns_zone'] = hParams[:dns_service]
596
- h_meta['dns_tenantid'] = hParams[:dns_tenant_id]
597
- h_meta['dns_auth_url'] = hParams[:auth_uri]
601
+ if hParams['dns#dns_service']
602
+ h_meta['dns_zone'] = hParams[:'dns#dns_service']
603
+ h_meta['dns_tenantid'] = hParams['dns#dns_tenant_id']
604
+ h_meta['dns_auth_url'] = hParams['credentials#auth_uri']
598
605
  end
599
606
  # If requested by user, ask Maestro to instantiate a blueprint.
600
607
  h_meta['blueprint'] = hParams[:blueprint] if hParams[:blueprint]
@@ -611,13 +618,15 @@ class ForjCoreProcess
611
618
  end
612
619
  end
613
620
 
621
+ tb_metadata hParams, h_meta
622
+
614
623
  h_meta
615
624
  end
616
625
 
617
626
  def build_metadata(sObjectType, hParams)
618
627
  entr = load_encoded_key
619
628
 
620
- os_enckey = hParams[:os_enckey]
629
+ os_enckey = hParams['credentials#os_enckey']
621
630
 
622
631
  os_key = decrypt_key(os_enckey, entr)
623
632
 
@@ -1280,11 +1289,11 @@ class ForjCoreProcess
1280
1289
  true
1281
1290
  end
1282
1291
 
1283
- def forj_dns_settings?(sKey)
1292
+ def forj_dns_settings?(key)
1284
1293
  # Return true to ask the question. false otherwise
1285
1294
  unless config[:dns_settings]
1286
- section = Lorj.data.first_section(sKey)
1287
- config.del(sKey, :name => 'account', :section => section)
1295
+ section, key = Lorj.data.first_section(key)
1296
+ config.del(key, :name => 'account', :section => section)
1288
1297
  return false # Do not ask
1289
1298
  end
1290
1299
  true
@@ -1379,7 +1388,6 @@ class ForjCoreProcess
1379
1388
 
1380
1389
  Lorj.data.set(:sections, :credentials, :keypair_files,
1381
1390
  { :desc => desc }, 'setup')
1382
-
1383
1391
  true
1384
1392
  end
1385
1393
  end
@@ -0,0 +1,120 @@
1
+ # encoding: UTF-8
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
+ # Functions for test-box
18
+ class ForjCoreProcess
19
+ # Function which detects the repository to send out to
20
+ # the box
21
+ #
22
+ # * *Args*:
23
+ # - +params+ : ObjParams. Take care of following data
24
+ # - :test_box : Hash. Key is the repo, and
25
+ # value a full path to the local repo.
26
+ # - :test_box_path : full path to the test-box.sh script
27
+ # - :public_ip: Used for ssh connections
28
+ # - :keypairs: Used for ssh connections
29
+ # - +log_output+ : log string to parse.
30
+ #
31
+ # * *returns* :
32
+ # - nothing.
33
+ #
34
+ def tb_detect(hParams, log_output)
35
+ return unless hParams[:test_box_path]
36
+ tb_repos = hParams[:test_box]
37
+ script = hParams[:test_box_path]
38
+
39
+ # the server must wait with 4 last lines in server log:
40
+ # [...] - forj-cli: tb-repo=maestro tb-dir=/opt/co[...] tb-root-repo=ma[...]
41
+ # [...] - build.sh: test-box-repo=maestro
42
+ # [...] - Test-box: Waiting for ~ubuntu/git/maestro.[...]
43
+ # [...] - On your workstation, you can start test-b [...]
44
+
45
+ re = /forj-cli: tb-repo=(.*) tb-dir=(.*) tb-root-repo=(.*)/
46
+ res = log_output.split("\n")[-4].match(re)
47
+
48
+ if res
49
+ repo_dir = "--repo-dir #{res[2]} --root-repo #{res[3]}"
50
+ else
51
+ res = log_output.split("\n")[-3].match(/build.sh: test-box-repo=(.*)/)
52
+ repo_dir = ''
53
+ end
54
+ return unless res && res[1] && tb_repos[res[1]]
55
+
56
+ repo = res[1]
57
+
58
+ test_box_dir = tb_repos[repo]
59
+
60
+ PrcLib.info('test-box: your box is waiting for a test-box repository. '\
61
+ 'One moment.')
62
+
63
+ # TODO : Add tb_ensure_ssh_config task to set this server in ~/.ssh/config.
64
+ # unless tb_ensure_ssh_config(hParams)
65
+ # PrcLib.info('test-box: Unable to configure ssh config with this server.'\
66
+ # ' You needs to do it yourself manually. Remote box boot '\
67
+ # "process is waiting for #{test_box_dir}")
68
+ # return
69
+ # end
70
+ PrcLib.warning('test-box: ssh config is currently not managed. You may '\
71
+ 'need to configure it yourself, otherwise test-box may fail')
72
+
73
+ pubip = hParams[:public_ip, :public_ip]
74
+ user = hParams[:image, :ssh_user]
75
+ # TODO: Implement testing branch warning. See build.sh lines 618 -> 632
76
+ cmd = <<-CMD
77
+ cd #{test_box_dir}
78
+ if [ "$(git branch | grep 'testing-larsonsh-#{user}@#{pubip}')" != "" ]
79
+ then
80
+ #{script} --remove-from #{user}@#{pubip} --repo #{repo} #{repo_dir}
81
+ fi
82
+ #{script} --push-to #{user}@#{pubip} --repo #{repo} #{repo_dir}
83
+ CMD
84
+ PrcLib.info "Running following shell instructions:\n#{cmd}"
85
+
86
+ return if system(cmd)
87
+
88
+ PrcLib.error('Unable to run test-box.sh successfully. You need to run it'\
89
+ ' yourself manually, now.')
90
+ loop do
91
+ break if ask("When you are done, type 'DONE'") == 'DONE'
92
+ end
93
+ end
94
+
95
+ # def tb_ensure_ssh_config(hParams)
96
+ # pubip = hParams[:public_ip, :name]
97
+ # user = hParams[:image, :ssh_user]
98
+ #
99
+ # ssh_config = Net::SSH::Config.new
100
+ # end
101
+
102
+ # function to add extra meta data to support test-box
103
+ #
104
+ # * *Args*:
105
+ # - metadata : Hash. Hash structure to update.
106
+ #
107
+ # * * returns*:
108
+ # - nothing
109
+ def tb_metadata(hParams, metadata)
110
+ # META['test-box']="test-box=$REPO_TO_ADD;testing-$(id -un)"
111
+ # else
112
+ # META['test-box']="${META['test-box']}|$REPO_TO_ADD;testing-$(id -un)"
113
+ return unless hParams.exist?(:test_box_path)
114
+
115
+ meta_str = `echo "testing-$(id -un)"`.split[0]
116
+ res = []
117
+ hParams[:test_box].each_key { |k| res << format('%s;%s', k, meta_str) }
118
+ metadata['test-box'] = res.join('|')
119
+ end
120
+ end
@@ -15,23 +15,12 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- # Defines how cli will control FORJ features
19
- # boot/down/ssh/...
18
+ FORJCORE_PATH = File.expand_path(File.dirname(__FILE__))
20
19
 
21
- # Define framework object on BaseDefinition
22
- # See lib/core/definition.rb for function details usage.
23
- class Lorj::BaseDefinition
24
- # ************************************ SSH Object
25
- define_obj(:ssh,
20
+ # Define model
26
21
 
27
- :create_e => :ssh_connection
28
- )
29
- obj_needs :CloudObject, :forge
30
- obj_needs :data, :instance_name
31
- obj_needs :data, :keypair_name
32
- obj_needs :data, :keypair_path
22
+ lorj_objects = %w(forj_process test_box declare)
33
23
 
34
- obj_needs_optional
35
- obj_needs :data, :forge_server
36
- obj_needs :data, :ssh_user
24
+ lorj_objects.each do |name|
25
+ load File.join(FORJCORE_PATH, 'forj_core', 'process', name + '.rb')
37
26
  end