fhcap-cli 0.4.6 → 0.4.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78bf8ef12f1a57a0cea0fb7d43f449ebaa837d3e
4
- data.tar.gz: 20bd845bfbed5c9adf26e8d4b5785737c5ed7a73
3
+ metadata.gz: 7442c785069713ce88491a3c794e162190f0d168
4
+ data.tar.gz: c84d4ad6ef141c6204822b10bf7ff022b18491c3
5
5
  SHA512:
6
- metadata.gz: 114792fc44c7c251413a224373f8ad1d196742eabac60c3dd65fb221194f2afa2be27c0e39d70dce77a9c99c631212aacd3001d2c79947bc37908acbcd5b5ea5
7
- data.tar.gz: 57d6da1fe18c0233a7cfeb02643c2c7a045b3fd3308f972fd013aaae72ee356d30f934c4a3b9e7aeedb1984c36019c53c6d6e99ea6a3c162a0ba2a1084af4f67
6
+ metadata.gz: bd8af02970b9092f546fe75419c14e65b0c1ecc665a6071ad89108a968c4f78f0fdb61a2d2426bb30941e90bb4bc112e233d85c360f20a4c335a734c106f0850
7
+ data.tar.gz: 3aacd843308e099f9c8e302f27eead3776410727e62b636acbe7fd00ae4b2ba19f932e68939346aa7fc0aee49788151b97a70f7e543cb51e2ce4eb79f61f5975
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ ## 0.4.7
3
+
4
+ * [RHMAP-6559] - Add ose-single template for AWS and OpenStack, creates a single node OpenShift Enterprise 3 instance.
5
+ * Make VPC optional on AWS clusters, will use the default VPC for the region if not specified.
6
+ * Removed self signed SSL cert creation during cluster generate.
7
+
2
8
  ## 0.4.6
3
9
 
4
10
  * [RHMAP-3031] - Add aws-tags (Name, Organisationm, Environment and Role) to all instances
@@ -54,13 +54,12 @@ def aws_bootstrap_options(org_name, environment, instance_options)
54
54
  image_id: instance_options[:image_id],
55
55
  instance_type: instance_options[:instance_type],
56
56
  key_name: key_pair_name_for(org_name)
57
- #key_path: "~/.chef/keys/chef_default"
58
57
  }
59
- bootstrap_options[:subnet] = subnet_name_for(org_name, environment, instance_options[:subnet])
58
+ bootstrap_options[:subnet] = subnet_name_for(org_name, environment, instance_options[:subnet]) if instance_options[:subnet]
60
59
  bootstrap_options[:security_group_ids] = instance_options[:security_groups].collect do |security_group|
61
60
  security_group_name_for(org_name, security_group)
62
- end
63
- bootstrap_options[:block_device_mappings] = instance_options[:block_device_mappings]
61
+ end if instance_options[:security_groups]
62
+ bootstrap_options[:block_device_mappings] = instance_options[:block_device_mappings] if instance_options[:block_device_mappings]
64
63
  bootstrap_options
65
64
  end
66
65
 
@@ -4,7 +4,10 @@ require 'chef/provisioning/aws_driver'
4
4
  require 'extensions/chef/provisioning/aws_driver/driver.rb'
5
5
 
6
6
  cluster_config = cluster_config_for(node)
7
- region = cluster_config[:vpc][:region]
7
+
8
+ raise "Missing aws region" unless cluster_config[:provider_config][:region]
9
+
10
+ region = cluster_config[:provider_config][:region]
8
11
  with_driver("aws:default:#{region}", {
9
12
  :aws_credentials => {
10
13
  "default" => {
@@ -12,53 +12,60 @@ aws_key_pair key_pair_name do
12
12
  public_key_path File.join(local_key_pairs_dir, "#{key_pair_name}.pub")
13
13
  end
14
14
 
15
+ vpc_name = nil
16
+ if cluster_config[:vpc]
15
17
  #Create VPC
16
- vpc_name = vpc_name_for(org_name)
18
+ vpc_name = vpc_name_for(org_name)
17
19
 
18
- aws_vpc vpc_name do
19
- cidr_block cluster_config[:vpc][:cidr]
20
- internet_gateway true
21
- main_routes '0.0.0.0/0' => :internet_gateway
20
+ aws_vpc vpc_name do
21
+ cidr_block cluster_config[:vpc][:cidr]
22
+ internet_gateway true
23
+ main_routes '0.0.0.0/0' => :internet_gateway
24
+ end
22
25
  end
23
26
 
27
+ if cluster_config[:security_groups]
24
28
  # Create Security Groups with empty rules first to avoid group dependent rule conflicts
25
- cluster_config[:security_groups].each do |sg_name, sg_config|
26
- aws_security_group security_group_name_for(org_name, sg_name) do
27
- vpc vpc_name
29
+ cluster_config[:security_groups].each do |sg_name, sg_config|
30
+ aws_security_group security_group_name_for(org_name, sg_name) do
31
+ vpc vpc_name
32
+ end
28
33
  end
29
- end
30
34
 
31
- # Create Security Groups
32
- cluster_config[:security_groups].each do |sg_name, sg_config|
33
- aws_security_group security_group_name_for(org_name, sg_name) do
34
- vpc vpc_name
35
- inbound_rules inbound_rules_for(org_name, sg_config[:authorize_ingress])
35
+ cluster_config[:security_groups].each do |sg_name, sg_config|
36
+ aws_security_group security_group_name_for(org_name, sg_name) do
37
+ vpc vpc_name
38
+ inbound_rules inbound_rules_for(org_name, sg_config[:authorize_ingress])
39
+ end
36
40
  end
37
41
  end
38
42
 
43
+ if vpc_name
39
44
  # Create Route Tables
40
- cluster_config[:environments].each do |env, env_config|
45
+ cluster_config[:environments].each do |env, env_config|
41
46
 
42
- env_route_table = route_table_name_for(org_name, env)
43
- aws_route_table env_route_table do
44
- vpc vpc_name
45
- routes '0.0.0.0/0' => :internet_gateway
46
- end
47
+ env_route_table = route_table_name_for(org_name, env)
48
+ aws_route_table env_route_table do
49
+ vpc vpc_name
50
+ routes '0.0.0.0/0' => :internet_gateway
51
+ end
47
52
 
48
- env_config[:subnets].each do |subnet_suffix, subnet_config|
53
+ env_config[:subnets].each do |subnet_suffix, subnet_config|
54
+
55
+ subnet_name = subnet_name_for(org_name, env, subnet_suffix)
56
+ aws_subnet subnet_name do
57
+ vpc vpc_name
58
+ cidr_block subnet_config[:cidr]
59
+ availability_zone subnet_config[:availability_zone]
60
+ route_table env_route_table
61
+ map_public_ip_on_launch true
62
+ end
49
63
 
50
- subnet_name = subnet_name_for(org_name, env, subnet_suffix)
51
- aws_subnet subnet_name do
52
- vpc vpc_name
53
- cidr_block subnet_config[:cidr]
54
- availability_zone subnet_config[:availability_zone]
55
- route_table env_route_table
56
- map_public_ip_on_launch true
57
64
  end
58
65
 
59
66
  end
60
-
61
67
  end
62
68
 
63
69
  include_recipe "provision::cluster_create_instances"
64
- include_recipe "provision::aws_cluster_create_elb"
70
+ include_recipe "provision::aws_cluster_create_elb"
71
+ include_recipe "provision::aws_cluster_create_eip"
@@ -0,0 +1,19 @@
1
+ include_recipe 'provision::common'
2
+ include_recipe "provision::aws"
3
+
4
+ with_cluster_instances(node) do |cluster_instances|
5
+ cluster_instances.each do |chef_environment, instances|
6
+ with_chef_environment chef_environment do
7
+
8
+ instances.each do |name, cfg|
9
+
10
+ aws_eip_address "#{name}-eip" do
11
+ machine name
12
+ associate_to_vpc true
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -5,6 +5,7 @@ cluster_config = cluster_config_for(node)
5
5
 
6
6
  org_name = cluster_config[:id]
7
7
 
8
+ include_recipe "provision::aws_cluster_destroy_eip"
8
9
  include_recipe "provision::cluster_destroy_instances"
9
10
 
10
11
  cluster_config[:environments].each do |env, env_config|
@@ -16,24 +17,28 @@ cluster_config[:environments].each do |env, env_config|
16
17
  end if env_config[:load_balancers]
17
18
  end
18
19
 
19
- # Clear all rules from Security Groups so that all dependent objects are cleared. This can potentially re-create security groups, so we have to force the destroy again below.
20
- cluster_config[:security_groups].each do |sg_name, sg_config|
21
- aws_security_group security_group_name_for(org_name, sg_name) do
22
- inbound_rules []
23
- end
24
- end
20
+ if cluster_config[:security_groups]
21
+ # Clear all rules from Security Groups so that all dependent objects are cleared. This can potentially re-create security groups, so we have to force the destroy again below.
22
+ cluster_config[:security_groups].each do |sg_name, sg_config|
23
+ aws_security_group security_group_name_for(org_name, sg_name) do
24
+ inbound_rules []
25
+ end
26
+ end if cluster_config[:security_groups]
25
27
 
26
- # Destroy all security groups. vpc purge would do this, but since we could have potentially re-created the group above, we do it here to be sure its removed.
27
- cluster_config[:security_groups].each do |sg_name, sg_config|
28
- aws_security_group security_group_name_for(org_name, sg_name) do
29
- action :destroy
30
- ignore_failure true
28
+ # Destroy all security groups. vpc purge would do this, but since we could have potentially re-created the group above, we do it here to be sure its removed.
29
+ cluster_config[:security_groups].each do |sg_name, sg_config|
30
+ aws_security_group security_group_name_for(org_name, sg_name) do
31
+ action :destroy
32
+ ignore_failure true
33
+ end
31
34
  end
32
35
  end
33
36
 
34
- vpc_name = vpc_name_for(org_name)
35
- aws_vpc vpc_name do
36
- action :purge
37
+ if cluster_config[:vpc]
38
+ vpc_name = vpc_name_for(org_name)
39
+ aws_vpc vpc_name do
40
+ action :purge
41
+ end
37
42
  end
38
43
 
39
44
  cluster_config[:environments].each do |env, env_config|
@@ -45,7 +50,7 @@ cluster_config[:environments].each do |env, env_config|
45
50
  aws_subnet subnet_name_for(org_name, env, subnet_suffix) do
46
51
  action :destroy
47
52
  end
48
- end
53
+ end if env_config[:subnets]
49
54
  end
50
55
 
51
56
  aws_key_pair key_pair_name_for(org_name) do
@@ -0,0 +1,15 @@
1
+ include_recipe 'provision::common'
2
+ include_recipe "provision::aws"
3
+
4
+ with_cluster_instances(node) do |cluster_instances|
5
+ cluster_instances.each do |chef_environment, instances|
6
+ with_chef_environment chef_environment do
7
+
8
+ instances.each do |name, cfg|
9
+ aws_eip_address "#{name}-eip" do
10
+ action :destroy
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ include_recipe 'provision::common'
2
+ include_recipe "provision::#{node['driver']}"
3
+
4
+ cluster_config = cluster_config_for(node)
5
+ org_name = cluster_config[:id]
6
+
7
+ cluster_config[:environments].each do |env, env_config|
8
+ chef_environment = fh_name_for(org_name, env)
9
+
10
+ installer_node = search(:node, "recipes:openshift\\:\\:installer AND chef_environment:#{chef_environment}").first
11
+
12
+ with_chef_environment chef_environment do
13
+
14
+ machine_execute "#{installer_node.name} run ose installer" do
15
+ command "su hadmin -c 'yes '' | atomic-openshift-installer --unattended --configuration /home/hadmin/.config/openshift/installer.cfg.yml install --force'"
16
+ live_stream true
17
+ machine installer_node.name
18
+ only_if { installer_node }
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ include_recipe 'provision::ose_post_install'
@@ -0,0 +1,30 @@
1
+ include_recipe 'provision::common'
2
+ include_recipe "provision::#{node['driver']}"
3
+
4
+ cluster_config = cluster_config_for(node)
5
+ org_name = cluster_config[:id]
6
+
7
+ cluster_config[:environments].each do |env, env_config|
8
+ chef_environment = fh_name_for(org_name, env)
9
+
10
+ installer_node = search(:node, "recipes:openshift\\:\\:installer AND chef_environment:#{chef_environment}").first
11
+
12
+ if installer_node
13
+ with_chef_environment chef_environment do
14
+ machine_execute "#{installer_node.name} create registry" do
15
+ command "oadm registry --service-account=registry --credentials=/etc/origin/master/openshift-registry.kubeconfig --images='registry.access.redhat.com/openshift3/ose-${component}:${version}'"
16
+ live_stream true
17
+ machine installer_node.name
18
+ only_if { installer_node }
19
+ end
20
+
21
+ machine_execute "#{installer_node.name} create router" do
22
+ command "oadm router default-router --service-account=router --credentials='/etc/origin/master/openshift-router.kubeconfig' --images='registry.access.redhat.com/openshift3/ose-${component}:${version}'"
23
+ live_stream true
24
+ machine installer_node.name
25
+ only_if { installer_node }
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -1,3 +1,8 @@
1
+ require 'chef'
2
+ require 'chef/knife'
3
+ require 'fhcap/tasks/chef/chef_zero_server'
4
+ require 'chef/knife/upload'
5
+ require 'chef/knife/download'
1
6
  require 'chef/config'
2
7
 
3
8
  module Fhcap
@@ -34,5 +39,118 @@ module Fhcap
34
39
  }
35
40
  end
36
41
 
42
+ def with_chef_server(cfg, &block)
43
+ ::Chef::Config.solo = false
44
+ if local_chef_server? cfg
45
+ with_local_chef_server(repo_dir(cfg[:repo]), &block)
46
+ else
47
+ block.call
48
+ end
49
+ end
50
+
51
+ def with_local_chef_server(local_repo, &block)
52
+ begin
53
+ ::Chef::Config.from_file(knife_config_file_for('local'))
54
+ uri = URI(::Chef::Config[:chef_server_url])
55
+ host = uri.hostname
56
+ port = uri.port
57
+ rescue
58
+ host = '127.0.0.1'
59
+ port = 7799
60
+ end
61
+
62
+ zero_server = Fhcap::Tasks::Chef::ChefZeroServer.new({host: host, port: port})
63
+
64
+ begin
65
+ zero_server.start_chef_zero_server
66
+ if zero_server.running?
67
+ thor.say "[Chef Zero Server] - running at #{zero_server.url}"
68
+ else
69
+ thor.say "[Chef Zero Server] - Failed to start server", :red
70
+ exit(-1)
71
+ end
72
+ rescue Errno::EADDRINUSE => e
73
+ thor.say "[Chef Zero Server] - Address in use (#{host}:#{port}), assuming this is ok"
74
+ end
75
+
76
+ thor.say "[Chef Zero Server] - Syncing nodes from #{local_repo}"
77
+ knife_upload(local_repo, 'local', ['/nodes'])
78
+ knife_upload(local_repo, 'local', ['/data_bags/aws_*'])
79
+ begin
80
+ block.call
81
+ ensure
82
+ thor.say "[Chef Zero Server] - Syncing nodes to #{local_repo}"
83
+ FileUtils.rm_rf(File.join(local_repo, 'nodes'))
84
+ FileUtils.rm_rf Dir.glob(File.join(local_repo, 'data_bags/aws_*'))
85
+ knife_download(local_repo, 'local', ['/nodes'])
86
+ knife_download(local_repo, 'local', ['/data_bags/aws_*'])
87
+ end
88
+ end
89
+
90
+ def local_chef_server?(cfg={})
91
+ cfg[:chef_server] && cfg[:chef_server] == 'local'
92
+ end
93
+
94
+ def knife_upload(repo, server, pattern)
95
+ thor.say " * uploading local repo items from #{repo} - #{pattern} ..."
96
+ suppress_stdout(!options[:verbose]) do
97
+ Dir.chdir(repo) do
98
+ ::Chef::Knife::Upload.load_deps
99
+ knife_command = ::Chef::Knife::Upload.new(pattern)
100
+ knife_command.config[:config_file] = knife_config_file_for(server)
101
+ knife_command.config[:chef_repo_path] = repo
102
+ knife_command.configure_chef
103
+ knife_command.config[:recurse] = true
104
+ knife_command.run
105
+ end
106
+ end
107
+ end
108
+
109
+ def knife_download(repo, server, pattern)
110
+ thor.say " * downloading server items to #{repo} - #{pattern} ..."
111
+ suppress_stdout(!options[:verbose]) do
112
+ Dir.chdir(repo) do
113
+ ::Chef::Knife::Download.load_deps
114
+ knife_command = ::Chef::Knife::Download.new(pattern)
115
+ knife_command.config[:config_file] = knife_config_file_for(server)
116
+ knife_command.config[:chef_repo_path] = repo
117
+ knife_command.configure_chef
118
+ knife_command.config[:recurse] = true
119
+ knife_command.run
120
+ end
121
+ end
122
+ end
123
+
124
+ def knife_environment_delete(env, server)
125
+ thor.say " * deleting environment '#{env}' from #{server}"
126
+ delete_chef_object(::Chef::Knife::EnvironmentDelete, server, env)
127
+ end
128
+
129
+ def knife_data_bag_delete(data_bag, item, server)
130
+ thor.say " * deleting data bag '#{data_bag} #{item}' from #{server}"
131
+ delete_chef_object(::Chef::Knife::DataBagDelete, server, data_bag, item)
132
+ end
133
+
134
+ def delete_chef_object(klass, server, *args)
135
+ begin
136
+ suppress_stdout(!options[:verbose]) do
137
+ klass.load_deps
138
+ knife_command = klass.new(args)
139
+ knife_command.config[:config_file] = knife_config_file_for(server)
140
+ knife_command.config[:yes] = true
141
+ knife_command.configure_chef
142
+ knife_command.run
143
+ end
144
+ rescue Net::HTTPServerException => e
145
+ response = e.response
146
+ case response
147
+ when Net::HTTPNotFound
148
+ puts "The object you are looking for could not be found, assuming this ok and continuing ..."
149
+ else
150
+ raise e
151
+ end
152
+ end
153
+ end
154
+
37
155
  end
38
156
  end
@@ -1,16 +1,13 @@
1
1
  require 'fhcap/tasks/chef/chef_task_base'
2
- require 'chef'
3
- require 'chef/knife'
4
- require 'fhcap/tasks/chef/chef_zero_server'
5
- require 'chef/knife/upload'
6
- require 'chef/knife/download'
7
- require 'chef/config'
2
+ require 'fhcap/knife_helper'
8
3
 
9
4
  module Fhcap
10
5
  module Tasks
11
6
  module Chef
12
7
  class ChefServerTask < ChefTaskBase
13
8
 
9
+ include Fhcap::KnifeHelper
10
+
14
11
  attr_reader :chef_server, :chef_repo, :repos
15
12
 
16
13
  def initialize(options)
@@ -23,117 +20,16 @@ module Fhcap
23
20
  def with_chef_server(&block)
24
21
  ::Chef::Config.solo = false
25
22
  if local_chef_server?
26
- with_local_chef_server(&block)
23
+ with_local_chef_server(repo_dir(@chef_repo), &block)
27
24
  else
28
25
  block.call
29
26
  end
30
27
  end
31
28
 
32
- def with_local_chef_server(&block)
33
- begin
34
- ::Chef::Config.from_file(knife_config_file_for('local'))
35
- uri = URI(::Chef::Config[:chef_server_url])
36
- host = uri.hostname
37
- port = uri.port
38
- rescue
39
- host = '127.0.0.1'
40
- port = 7799
41
- end
42
-
43
- zero_server = Fhcap::Tasks::Chef::ChefZeroServer.new({host: host, port: port})
44
-
45
- begin
46
- zero_server.start_chef_zero_server
47
- if zero_server.running?
48
- thor.say "[Chef Zero Server] - running at #{zero_server.url}"
49
- else
50
- thor.say "[Chef Zero Server] - Failed to start server", :red
51
- exit(-1)
52
- end
53
- rescue Errno::EADDRINUSE => e
54
- thor.say "[Chef Zero Server] - Address in use (#{host}:#{port}), assuming this is ok"
55
- end
56
-
57
- local_repo = repo_dir(@chef_repo)
58
- thor.say "[Chef Zero Server] - Syncing nodes from #{local_repo}"
59
- knife_upload(local_repo, @chef_server, ['/nodes'])
60
- knife_upload(local_repo, @chef_server, ['/data_bags/aws_*'])
61
- begin
62
- block.call
63
- ensure
64
- thor.say "[Chef Zero Server] - Syncing nodes to #{local_repo}"
65
- FileUtils.rm_rf(File.join(local_repo, 'nodes'))
66
- FileUtils.rm_rf Dir.glob(File.join(local_repo, 'data_bags/aws_*'))
67
- knife_download(local_repo, @chef_server, ['/nodes'])
68
- knife_download(local_repo, @chef_server, ['/data_bags/aws_*'])
69
- end
70
- end
71
-
72
29
  def local_chef_server?
73
30
  chef_server && chef_server == 'local'
74
31
  end
75
32
 
76
- def knife_upload(repo, server, pattern)
77
- thor.say " * uploading local repo items from #{repo} - #{pattern} ..."
78
- suppress_stdout(!options[:verbose]) do
79
- Dir.chdir(repo) do
80
- ::Chef::Knife::Upload.load_deps
81
- knife_command = ::Chef::Knife::Upload.new(pattern)
82
- knife_command.config[:config_file] = knife_config_file_for(server)
83
- knife_command.config[:chef_repo_path] = repo
84
- knife_command.configure_chef
85
- knife_command.config[:recurse] = true
86
- knife_command.run
87
- end
88
- end
89
- end
90
-
91
- def knife_download(repo, server, pattern)
92
- thor.say " * downloading server items to #{repo} - #{pattern} ..."
93
- suppress_stdout(!options[:verbose]) do
94
- Dir.chdir(repo) do
95
- ::Chef::Knife::Download.load_deps
96
- knife_command = ::Chef::Knife::Download.new(pattern)
97
- knife_command.config[:config_file] = knife_config_file_for(server)
98
- knife_command.config[:chef_repo_path] = repo
99
- knife_command.configure_chef
100
- knife_command.config[:recurse] = true
101
- knife_command.run
102
- end
103
- end
104
- end
105
-
106
- def knife_environment_delete(env, server)
107
- thor.say " * deleting environment '#{env}' from #{server}"
108
- delete_chef_object(::Chef::Knife::EnvironmentDelete, server, env)
109
- end
110
-
111
- def knife_data_bag_delete(data_bag, item, server)
112
- thor.say " * deleting data bag '#{data_bag} #{item}' from #{server}"
113
- delete_chef_object(::Chef::Knife::DataBagDelete, server, data_bag, item)
114
- end
115
-
116
- def delete_chef_object(klass, server, *args)
117
- begin
118
- suppress_stdout(!options[:verbose]) do
119
- klass.load_deps
120
- knife_command = klass.new(args)
121
- knife_command.config[:config_file] = knife_config_file_for(server)
122
- knife_command.config[:yes] = true
123
- knife_command.configure_chef
124
- knife_command.run
125
- end
126
- rescue Net::HTTPServerException => e
127
- response = e.response
128
- case response
129
- when Net::HTTPNotFound
130
- puts "The object you are looking for could not be found, assuming this ok and continuing ..."
131
- else
132
- raise e
133
- end
134
- end
135
- end
136
-
137
33
  end
138
34
  end
139
35
  end
@@ -83,6 +83,7 @@ module Fhcap
83
83
  config[user.to_sym][:ssh_public_key] = key.ssh_public_key
84
84
  config[user.to_sym][:ssh_private_key] = key.private_key
85
85
  end
86
+ config[:users][:hadmin][:ssh_keys] << config[:users][:hadmin][:ssh_public_key]
86
87
  config[:users][:hadmin][:ssh_keys] << config[:nagios_user][:ssh_public_key]
87
88
 
88
89
  #root_user
@@ -15,7 +15,8 @@ module Fhcap
15
15
 
16
16
  unless options[:'skip-provision']
17
17
  do_chef_run("provision::cluster_bootstrap")
18
- seed_cookbooks if local_chef_server?
18
+ #ToDo Do we need this anymore?
19
+ #seed_cookbooks if local_chef_server?
19
20
  do_chef_run("provision::post_create_instances")
20
21
 
21
22
  #Need to set run list correctly here after post create stuff since provision no longer does it
@@ -1,4 +1,5 @@
1
1
  require 'fhcap/tasks/cluster/cluster_task_base'
2
+ require 'fhcap/knife_helper'
2
3
  require "fhcap/tasks/dns/create_record"
3
4
 
4
5
  module Fhcap
@@ -6,13 +7,18 @@ module Fhcap
6
7
  module Cluster
7
8
  class CreateDNSRecords < ClusterTaskBase
8
9
 
10
+ include Fhcap::KnifeHelper
11
+
9
12
  def initialize(options)
10
13
  super(options)
11
14
  end
12
15
 
13
16
  def run
14
17
  thor.say "Cluster::CreateDNSRecords", :yellow
15
- create_dns_record
18
+ with_chef_server(cluster_config) do
19
+ create_dns_record
20
+ create_records_openshift
21
+ end
16
22
  end
17
23
 
18
24
  private
@@ -65,29 +71,41 @@ module Fhcap
65
71
  end
66
72
 
67
73
  def create_dns_record_openstack
74
+ create_records_for_query("recipes:nginx_feedhenry\\:\\:loadbalancer", ["*"])
75
+ end
76
+
77
+ def create_records_openshift
78
+ #This is a very basic openshift DNS setup and does not take into account a HA setup or LBs
79
+ create_records_for_query("roles:ose_master_server", [""])
80
+ create_records_for_query("roles:ose_node_server", ["*"])
81
+ end
82
+
83
+ def create_records_for_query(query, records)
68
84
  cluster_config[:environments].each do |env_name, env_cfg|
69
85
  env_name = "#{name}-#{env_name}"
70
86
  knife_config_file = knife_config_file_for(cluster_config[:chef_server])
71
87
  #ToDo [RHMAP-2898] Use knife object
72
- nodes = JSON.parse(`knife search "chef_environment:#{env_name} AND recipes:nginx_feedhenry\\:\\:loadbalancer" -c #{knife_config_file} -F json -a name -a cloud.public_ipv4`)
88
+ nodes = JSON.parse(`knife search "chef_environment:#{env_name} AND #{query}" -c #{knife_config_file} -F json -a name -a cloud.public_ipv4`)
73
89
 
74
- lb_node = nodes['rows'].collect do |row|
90
+ query_node = nodes['rows'].collect do |row|
75
91
  name, attrs = row.first
76
92
  attrs
77
93
  end.first
78
94
 
79
- if lb_node
80
- if lb_node['cloud.public_ipv4']
81
- dns_record_cfg = {
82
- domain: "*.#{env_cfg[:domain]}",
83
- ipaddress: lb_node['cloud.public_ipv4']
84
- }
85
- Dns::CreateRecord.new(@options.dup.merge(dns_record_cfg)).run
95
+ if query_node
96
+ if query_node['cloud.public_ipv4']
97
+ records.each do |record|
98
+ dns_record_cfg = {
99
+ domain: [record, env_cfg[:domain]].compact.reject(&:empty?).join('.'),
100
+ ipaddress: query_node['cloud.public_ipv4']
101
+ }
102
+ Dns::CreateRecord.new(@options.dup.merge(dns_record_cfg)).run
103
+ end
86
104
  else
87
- thor.say "Found lb node '#{lb_node['name']}', but was unable to retrieve it's IP!!}"
105
+ thor.say "Found query node '#{query_node['name']}', but was unable to retrieve it's IP!!}"
88
106
  end
89
107
  else
90
- thor.say "Unable to locate lb node in cluster!!"
108
+ thor.say "Unable to locate node for query '#{query}' in cluster!!"
91
109
  end
92
110
  end
93
111
  end
@@ -49,7 +49,6 @@ module Fhcap
49
49
  }
50
50
  generate_environment_config
51
51
  create_chef_environment(env_cfg)
52
- create_ssl_cert(env_cfg)
53
52
  thor.create_file(cluster_file, JSON.pretty_generate(cluster_config)) unless @skip_create_cluster_file
54
53
  end
55
54
 
@@ -159,6 +158,8 @@ module Fhcap
159
158
  'core'
160
159
  when /mbaas/
161
160
  'mbaas'
161
+ when /ose-single/
162
+ 'ose-single'
162
163
  when /single/
163
164
  'single'
164
165
  when /farm/
@@ -87,6 +87,7 @@ module Fhcap
87
87
  ask_config(required_config, cluster_config)
88
88
  cluster_config[:driver] = provider_type(cluster_config[:provider_id])
89
89
  send(:"generate_cluster_config_#{cluster_config[:driver]}")
90
+ generate_machine_options
90
91
  driver_template_file = File.join(Fhcap.source_root, 'templates', 'cluster', cluster_config[:driver], "common.json.erb")
91
92
  driver_template_config = template_as_object(driver_template_file, cluster_config)
92
93
  cluster_config.merge!(driver_template_config)
@@ -94,17 +95,30 @@ module Fhcap
94
95
 
95
96
  def generate_cluster_config_aws
96
97
  ask_config(aws_required_config, cluster_config[:provider_config])
97
- aws_regions = provider_config(cluster_config[:provider_id])[:regions]
98
98
  cluster_config[:default_instance_options] = cluster_config[:default_instance_options] || {}
99
- cluster_config[:default_instance_options][:image_id] = aws_regions[cluster_config[:provider_config][:region].to_sym][:base_image]
99
+ default_provider_conf = provider_config(@cluster_config[:provider_id])
100
+ aws_regions = default_provider_conf[:regions]
101
+ cluster_config[:default_instance_options][:image_id] = cluster_config[:provider_config][:image_id] || aws_regions[cluster_config[:provider_config][:region].to_sym][:base_image]
102
+ cluster_config[:default_instance_options][:instance_type] = cluster_config[:provider_config][:instance_type] || default_provider_conf[:instance_type]
100
103
  end
101
104
 
102
105
  def generate_cluster_config_openstack
103
106
  cluster_config[:default_instance_options] = cluster_config[:default_instance_options] || {}
104
- cluster_config[:default_instance_options][:image_ref] = provider_config(@cluster_config[:provider_id])[:image_ref]
105
- cluster_config[:default_instance_options][:flavor_ref] = provider_config(@cluster_config[:provider_id])[:flavor_ref]
106
- cluster_config[:default_instance_options][:floating_ip_pool] = provider_config(@cluster_config[:provider_id])[:floating_ip_pool]
107
- cluster_config[:default_instance_options][:ssh_username] = provider_config(@cluster_config[:provider_id])[:ssh_username]
107
+ default_provider_conf = provider_config(@cluster_config[:provider_id])
108
+ cluster_config[:default_instance_options][:image_ref] = cluster_config[:provider_config][:image_ref] || default_provider_conf[:image_ref]
109
+ cluster_config[:default_instance_options][:flavor_ref] = cluster_config[:provider_config][:flavor_ref] || default_provider_conf[:flavor_ref]
110
+ cluster_config[:default_instance_options][:floating_ip_pool] = cluster_config[:provider_config][:floating_ip_pool] || default_provider_conf[:floating_ip_pool]
111
+ cluster_config[:default_instance_options][:ssh_username] = cluster_config[:provider_config][:ssh_username] || default_provider_conf[:ssh_username]
112
+ end
113
+
114
+ def generate_machine_options
115
+ cluster_config[:machine_options] = cluster_config[:machine_options] || {}
116
+ cluster_config[:machine_options][:ssh_username] = cluster_config[:provider_config][:ssh_username] || 'ubuntu'
117
+ cluster_config[:machine_options][:convergence_options] = cluster_config[:machine_options][:convergence_options] || {}
118
+ cluster_config[:machine_options][:convergence_options][:chef_version] = "12.6.0"
119
+ cluster_config[:machine_options][:convergence_options][:ssl_verify_mode] = "verify_none"
120
+ cluster_config[:machine_options][:convergence_options][:ohai_hints] = cluster_config[:machine_options][:convergence_options][:ohai_hints] || {}
121
+ cluster_config[:machine_options][:convergence_options][:ohai_hints][cluster_config[:driver].to_sym] = {}
108
122
  end
109
123
 
110
124
  def generate_cluster_environments
data/lib/fhcap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fhcap
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
data/lib/fhcap.rb CHANGED
@@ -3,7 +3,7 @@ require "pathname"
3
3
 
4
4
  module Fhcap
5
5
  GEM_DIR = File.expand_path '..', File.dirname(__FILE__)
6
- TEMPLATE_NAMES = %w{single core-3node mbaas-3node core-mbaas-6node core-small-9node nginx-test single-blank farm-3node farm-single}.sort
6
+ TEMPLATE_NAMES = %w{single core-3node mbaas-3node core-mbaas-6node core-small-9node nginx-test single-blank farm-3node farm-single ose-single}.sort
7
7
 
8
8
  class << self
9
9
  def source_root
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "<%= config[:name] %>",
3
+ "description": "<%= config[:name] %> Environment",
4
+ "cookbook_versions": {
5
+ },
6
+ "json_class": "Chef::Environment",
7
+ "chef_type": "environment",
8
+ "default_attributes": {
9
+ "openshift": {
10
+ "domain": "<%= config[:domain] %>"
11
+ },
12
+ "rhsm": {
13
+ "username": "CHANGEME",
14
+ "password": "CHANGEME"
15
+ },
16
+ "resolver": {
17
+ "nameservers": [
18
+ "8.8.8.8",
19
+ "8.8.4.4"
20
+ ]
21
+ }
22
+ },
23
+ "override_attributes": {
24
+ "authorization": {
25
+ "sudo": {
26
+ "passwordless": true
27
+ }
28
+ }
29
+ }
30
+ }
@@ -1,8 +1,14 @@
1
+ <%-
2
+ require 'open-uri'
3
+ @my_public_ip = open('http://whatismyip.akamai.com').read
4
+ -%>
1
5
  {
6
+ <%- unless config[:provider_config][:cidr] == "none" %>
2
7
  "vpc": {
3
8
  "region": "<%= config[:provider_config][:region] %>",
4
9
  "cidr": "<%= config[:provider_config][:cidr] %>"
5
10
  },
11
+ <%- end %>
6
12
  "default_instance_options": {
7
13
  "image_id": "<%= config[:default_instance_options][:image_id] %>",
8
14
  "monitoring_enabled": true,
@@ -35,7 +41,7 @@
35
41
  "protocols": ["all"],
36
42
  "start": 0,
37
43
  "end": 65535,
38
- "sources": ["83.147.149.210/32", "46.38.161.225/32", "54.229.76.48/32", "79.125.117.182/32", "78.137.150.209/32", "52.37.106.23", "52.50.12.70", "52.62.158.176", "52.70.198.93", "52.193.17.19", "52.86.106.110", "52.48.49.57"]
44
+ "sources": ["<%= @my_public_ip %>", "83.147.149.210/32", "46.38.161.225/32", "54.229.76.48/32", "79.125.117.182/32", "78.137.150.209/32", "52.37.106.23", "52.50.12.70", "52.62.158.176", "52.70.198.93", "52.193.17.19", "52.86.106.110", "52.48.49.57"]
39
45
  }
40
46
  ]
41
47
  },
@@ -0,0 +1,78 @@
1
+ {
2
+ "domain": "<%= config[:domain] %>",
3
+ "security_groups": {
4
+ "oseinternal": {
5
+ "authorize_ingress": [
6
+ {
7
+ "protocols": [
8
+ "all"
9
+ ],
10
+ "start": 0,
11
+ "end": 65535,
12
+ "groups": [
13
+ "oseinternal"
14
+ ]
15
+ },
16
+ {
17
+ "protocols": [
18
+ "icmp"
19
+ ],
20
+ "start": -1,
21
+ "end": -1,
22
+ "groups": [
23
+ "oseinternal"
24
+ ]
25
+ }
26
+ ]
27
+ },
28
+ "oseexternal": {
29
+ "authorize_ingress": [
30
+ {
31
+ "protocols": [
32
+ "tcp"
33
+ ],
34
+ "start": 80,
35
+ "end": 80,
36
+ "sources": [
37
+ "0.0.0.0/0"
38
+ ]
39
+ },
40
+ {
41
+ "protocols": [
42
+ "tcp"
43
+ ],
44
+ "start": 443,
45
+ "end": 443,
46
+ "sources": [
47
+ "0.0.0.0/0"
48
+ ]
49
+ },
50
+ {
51
+ "protocols": [
52
+ "tcp"
53
+ ],
54
+ "start": 8443,
55
+ "end": 8443,
56
+ "sources": [
57
+ "0.0.0.0/0"
58
+ ]
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ "instances": {
64
+ "node1": {
65
+ "aws": {
66
+ "security_groups": [
67
+ "ops-admin",
68
+ "oseinternal",
69
+ "oseexternal"
70
+ ]
71
+ },
72
+ "run_list": [
73
+ "role[ose_master_server]",
74
+ "role[ose_node_server]"
75
+ ]
76
+ }
77
+ }
78
+ }
@@ -22,12 +22,6 @@
22
22
  "start": 80,
23
23
  "end": 80,
24
24
  "sources": ["0.0.0.0/0"]
25
- },
26
- {
27
- "protocols": ["tcp"],
28
- "start": 443,
29
- "end": 443,
30
- "sources": ["0.0.0.0/0"]
31
25
  }
32
26
  ]
33
27
  },
@@ -75,13 +69,6 @@
75
69
  "protocol": "http",
76
70
  "instance_port": 80,
77
71
  "instance_protocol": "http"
78
- },
79
- {
80
- "port": 443,
81
- "protocol": "https",
82
- "instance_port": 80,
83
- "instance_protocol": "http",
84
- "server_certificate": ""
85
72
  }
86
73
  ]
87
74
  }
@@ -0,0 +1,11 @@
1
+ {
2
+ "domain": "<%= config[:domain] %>",
3
+ "instances": {
4
+ "node1": {
5
+ "run_list": [
6
+ "role[ose_master_server]",
7
+ "role[ose_node_server]"
8
+ ]
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "environments": [
3
+ {
4
+ "name": "ose-single",
5
+ "template": "ose-single"
6
+ }
7
+ ]
8
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fhcap-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Nairn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -396,8 +396,10 @@ files:
396
396
  - lib/cookbooks/provision/metadata.rb
397
397
  - lib/cookbooks/provision/recipes/aws.rb
398
398
  - lib/cookbooks/provision/recipes/aws_cluster_create.rb
399
+ - lib/cookbooks/provision/recipes/aws_cluster_create_eip.rb
399
400
  - lib/cookbooks/provision/recipes/aws_cluster_create_elb.rb
400
401
  - lib/cookbooks/provision/recipes/aws_cluster_destroy.rb
402
+ - lib/cookbooks/provision/recipes/aws_cluster_destroy_eip.rb
401
403
  - lib/cookbooks/provision/recipes/cluster_bootstrap.rb
402
404
  - lib/cookbooks/provision/recipes/cluster_bootstrap_instances.rb
403
405
  - lib/cookbooks/provision/recipes/cluster_create.rb
@@ -414,6 +416,8 @@ files:
414
416
  - lib/cookbooks/provision/recipes/openstack.rb
415
417
  - lib/cookbooks/provision/recipes/openstack_cluster_create.rb
416
418
  - lib/cookbooks/provision/recipes/openstack_cluster_destroy.rb
419
+ - lib/cookbooks/provision/recipes/ose_install.rb
420
+ - lib/cookbooks/provision/recipes/ose_post_install.rb
417
421
  - lib/cookbooks/provision/recipes/post_create_instances.rb
418
422
  - lib/cookbooks/provision/recipes/rabbitmq_reset_cluster.rb
419
423
  - lib/cookbooks/provision/recipes/restart_services.rb
@@ -530,6 +534,7 @@ files:
530
534
  - templates/chef/environment_empty.json.erb
531
535
  - templates/chef/environment_farm.json.erb
532
536
  - templates/chef/environment_mbaas.json.erb
537
+ - templates/chef/environment_ose-single.json.erb
533
538
  - templates/chef/environment_single.json.erb
534
539
  - templates/cluster/aws/common.json.erb
535
540
  - templates/cluster/aws/core-3node.json.erb
@@ -538,6 +543,7 @@ files:
538
543
  - templates/cluster/aws/farm-single.json.erb
539
544
  - templates/cluster/aws/mbaas-3node.json.erb
540
545
  - templates/cluster/aws/nginx-test.json.erb
546
+ - templates/cluster/aws/ose-single.json.erb
541
547
  - templates/cluster/aws/single-blank.json.erb
542
548
  - templates/cluster/aws/single.json.erb
543
549
  - templates/cluster/core-3node.json.erb
@@ -554,8 +560,10 @@ files:
554
560
  - templates/cluster/openstack/farm-single.json.erb
555
561
  - templates/cluster/openstack/mbaas-3node.json.erb
556
562
  - templates/cluster/openstack/nginx-test.json.erb
563
+ - templates/cluster/openstack/ose-single.json.erb
557
564
  - templates/cluster/openstack/single-blank.json.erb
558
565
  - templates/cluster/openstack/single.json.erb
566
+ - templates/cluster/ose-single.json.erb
559
567
  - templates/cluster/single-blank.json.erb
560
568
  - templates/cluster/single.json.erb
561
569
  - templates/init/knife.rb.erb
@@ -586,7 +594,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
586
594
  version: 2.5.0
587
595
  requirements: []
588
596
  rubyforge_project:
589
- rubygems_version: 2.4.8
597
+ rubygems_version: 2.6.4
590
598
  signing_key:
591
599
  specification_version: 4
592
600
  summary: FHCAP Command Line Tool