knife-clc-chef-server 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aee3d53c78370e8cb2150027a3d44d1f2f787ef4
4
+ data.tar.gz: e02688ed11531f156a514bf10113b347ffc07703
5
+ SHA512:
6
+ metadata.gz: f017c671d5583ef34430513c164b18bfd9383ec31faf0a52b1065d424fad306c8f0a17f9fa88bddc5bbebb29dfca679c635fb411a2575da4eb1b1f38d9474849
7
+ data.tar.gz: 0420051c279b1601fbf32176d49095aeae74fbc1ebc9f516bd869b0395817b09b5814d44a2f97348b3ad8e716b2f2521b5fbaae447eaf22e066ca448d2730831
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clc_chef_server.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 mwrock
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ClcChefServer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'clc_chef_server'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install clc_chef_server
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/clc_chef_server/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ module Bundler
4
+ class GemHelper
5
+ def rubygem_push(path)
6
+ gems = Dir.glob(File.join(File.dirname(__FILE__), 'pkg', 'knife-clc-chef-server-*.gem'))
7
+ system("gem push '#{gems[0]}' --host http://172.22.10.137:8081/artifactory/api/gems/localgems -k clc_api_key")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clc_chef_server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "knife-clc-chef-server"
8
+ spec.version = ClcChefServer::VERSION
9
+ spec.authors = ['CenturyLink Cloud']
10
+ spec.email = ["matt.wrock@ctl.io"]
11
+ spec.summary = 'Create sandbox organizations and deploy chef nodes'
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,45 @@
1
+ require 'chef/knife'
2
+ require 'clc_chef_server'
3
+
4
+ module KnifeClcServer
5
+ class ClientRun < Chef::Knife
6
+
7
+ banner "knife client run ENVIRONMENT"
8
+
9
+ option :node,
10
+ :short => "-n NODE",
11
+ :long => "--node NODE",
12
+ :description => "chef node to run (QA3T3NPROVISIONER01 is the default)",
13
+ :default => "QA3T3NPROVISIONER01"
14
+
15
+ option :clusters,
16
+ :short => "-C CLUSTERS",
17
+ :long => "--clusters CLUSTERS",
18
+ :description => "comma delimited list of clusters to provision (Defaults to all clusters)"
19
+
20
+ option :ssh_user,
21
+ :short => "-x SSH_USER",
22
+ :long => "--ssh_user SSH_USER",
23
+ :description => "ssh user used to login to node - defaults to 'root'",
24
+ :default => "root"
25
+
26
+ option :ssh_password,
27
+ :short => "-P SSH_PASSWORD",
28
+ :long => "--ssh_password SSH_PASSWORD",
29
+ :description => "ssh password used to login to node - defaults to 'Password123'",
30
+ :default => "Password123"
31
+
32
+ def run
33
+ if @name_args.length < 1
34
+ show_usage
35
+ ui.error("You must specify an environment to target")
36
+ exit 1
37
+ end
38
+
39
+ server_path = URI(Chef::Config[:chef_server_url]).path
40
+ org = server_path[server_path.rindex('/')+1..-1]
41
+
42
+ ClcChefServer.client_run(org, config[:node], config[:clusters], @name_args[0], config[:ssh_user], config[:ssh_password])
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ require 'chef/knife'
2
+ require 'clc_chef_server'
3
+
4
+ module KnifeClcServer
5
+ class ServerSandbox < Chef::Knife
6
+
7
+ banner "knife server sandbox ENVIRONMENT"
8
+
9
+ def run
10
+ if @name_args.length < 1
11
+ show_usage
12
+ ui.error("You must specify an organization to create")
13
+ exit 1
14
+ end
15
+
16
+ ClcChefServer.create_sandbox(@name_args[0], ui)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,83 @@
1
+ require 'chef'
2
+ require 'chef/chef_fs/file_system/chef_repository_file_system_root_dir'
3
+ require "clc_chef_server/version"
4
+
5
+ module ClcChefServer
6
+ class << self
7
+ TMP_DIR = '/tmp/clc_chef_server/cookbooks'
8
+
9
+ def create_sandbox(organization, ui = nil)
10
+ repo = Chef::Config.find_chef_repo_path(Dir.pwd)
11
+ chef_server = URI(Chef::Config[:chef_server_url]).host
12
+ Chef::Config[:cookbook_path] = TMP_DIR
13
+
14
+ %w[clc_library chef_server chef-vault chef-client cron logrotate newrelic].each do |cb|
15
+ download_cookbook(cb, ui)
16
+ end
17
+
18
+ command = <<-EOS
19
+ echo '{
20
+ "chef_server": {
21
+ "repo_path": "#{repo}",
22
+ "organization": "#{organization}",
23
+ "chef_server_ip": "#{chef_server}",
24
+ "client_username": "provisioner_#{organization}"
25
+ }
26
+ }' | sudo -E chef-client -z \\
27
+ -o 'clc_library,chef_server::organization_sandbox' \\
28
+ -j /dev/stdin
29
+ EOS
30
+ shell(command)
31
+ end
32
+
33
+ def client_run(organization, node, clusters, environment, ssh_user, ssh_password)
34
+ repo = Chef::Config.find_chef_repo_path(Dir.pwd)
35
+ knife_path = "#{repo}/.chef/knife_#{organization}.rb"
36
+ puts "Searching chef server for node #{node}..."
37
+ out = `knife search 'name:#{node}' -c #{knife_path} -a metal.location.ipaddress`
38
+ ip=out[/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/]
39
+ if system("ssh-keygen -F #{ip} -f ~/.ssh/known_hosts > /dev/null")
40
+ system("ssh-keygen -f ~/.ssh/known_hosts -R #{ip} > /dev/null")
41
+ end
42
+
43
+ command = <<-EOS
44
+ knife ssh "name:#{node}" "echo '{
45
+ \\"provisioner\\": {
46
+ \\"clusters\\": \\"#{clusters}\\"
47
+ }
48
+ }' | chef-client -E #{environment} \\
49
+ -l info \\
50
+ -j /dev/stdin" -x #{ssh_user} -P #{ssh_password} -c #{knife_path} --attribute metal.location.ipaddress
51
+ EOS
52
+ shell(command)
53
+ end
54
+
55
+ private
56
+
57
+ def download_cookbook(cookbook, ui)
58
+ cookbook_path = File.join("/cookbooks", cookbook)
59
+ download_chef_files(cookbook_path, ui) unless Dir.exist?(cookbook_path)
60
+ end
61
+
62
+ def download_chef_files(path, ui)
63
+ FileUtils.mkdir_p(TMP_DIR) if !Dir.exist?(TMP_DIR)
64
+
65
+ fs_config = Chef::ChefFS::Config.new(Chef::Config, cwd = Dir.pwd)
66
+ pattern = Chef::ChefFS::FilePattern.new(path)
67
+ local = Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir.new(
68
+ {
69
+ 'environments' => [File.join(TMP_DIR, 'environments')],
70
+ 'data_bags' => [File.join(TMP_DIR, 'data_bags')],
71
+ 'cookbooks' => [File.join(TMP_DIR, 'cookbooks')],
72
+ }
73
+ )
74
+ Chef::ChefFS::FileSystem.copy_to(pattern, fs_config.chef_fs, local, nil, Chef::Config)
75
+ end
76
+
77
+ def shell(command)
78
+ puts ""
79
+ puts command
80
+ system(command)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module ClcChefServer
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-clc-chef-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - CenturyLink Cloud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Create sandbox organizations and deploy chef nodes
42
+ email:
43
+ - matt.wrock@ctl.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - knife-clc-chef-server.gemspec
54
+ - lib/chef/knife/client_run.rb
55
+ - lib/chef/knife/server_sandbox.rb
56
+ - lib/clc_chef_server.rb
57
+ - lib/clc_chef_server/version.rb
58
+ homepage: ''
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Create sandbox organizations and deploy chef nodes
81
+ test_files: []
82
+ has_rdoc: