knife-clc-chef-server 0.1.0 → 0.4.2

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: aee3d53c78370e8cb2150027a3d44d1f2f787ef4
4
- data.tar.gz: e02688ed11531f156a514bf10113b347ffc07703
3
+ metadata.gz: f4e86c5562cbe1bdfd540be428333864df3b5a2e
4
+ data.tar.gz: 6b4ce1e3a07ad2a9c0cb1b294d26aab73f37ae1b
5
5
  SHA512:
6
- metadata.gz: f017c671d5583ef34430513c164b18bfd9383ec31faf0a52b1065d424fad306c8f0a17f9fa88bddc5bbebb29dfca679c635fb411a2575da4eb1b1f38d9474849
7
- data.tar.gz: 0420051c279b1601fbf32176d49095aeae74fbc1ebc9f516bd869b0395817b09b5814d44a2f97348b3ad8e716b2f2521b5fbaae447eaf22e066ca448d2730831
6
+ metadata.gz: a6972cc8d5a608ab0fb7d01efca456975cda0f273901f142dccf663a41c426e5958d32f9c3729e5dd646417ef181f48ad9602437394565d724cb96f480e2e25d
7
+ data.tar.gz: 0649cdd39f962c8034a84c5646972016661d48c0f7194d83b26bca928b546af6c19ead52315816a6a7e0f29bad4ea1d88ab525d782463d60b1ce47f451ff6f6d
data/Rakefile CHANGED
@@ -1,10 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
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
@@ -2,9 +2,9 @@ require 'chef/knife'
2
2
  require 'clc_chef_server'
3
3
 
4
4
  module KnifeClcServer
5
- class ClientRun < Chef::Knife
5
+ class Provision < Chef::Knife
6
6
 
7
- banner "knife client run ENVIRONMENT"
7
+ banner "knife provision CLUSTERS -E ENVIRONMENT"
8
8
 
9
9
  option :node,
10
10
  :short => "-n NODE",
@@ -12,11 +12,6 @@ module KnifeClcServer
12
12
  :description => "chef node to run (QA3T3NPROVISIONER01 is the default)",
13
13
  :default => "QA3T3NPROVISIONER01"
14
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
15
  option :ssh_user,
21
16
  :short => "-x SSH_USER",
22
17
  :long => "--ssh_user SSH_USER",
@@ -29,8 +24,19 @@ module KnifeClcServer
29
24
  :description => "ssh password used to login to node - defaults to 'Password123'",
30
25
  :default => "Password123"
31
26
 
27
+ option :no_converge,
28
+ :long => "--no_converge",
29
+ :description => "do not converge the node. Just create it.",
30
+ :default => false
31
+
32
32
  def run
33
33
  if @name_args.length < 1
34
+ show_usage
35
+ ui.error("You must specify one or more clusters to provision")
36
+ exit 1
37
+ end
38
+
39
+ if config[:environment].nil?
34
40
  show_usage
35
41
  ui.error("You must specify an environment to target")
36
42
  exit 1
@@ -39,7 +45,16 @@ module KnifeClcServer
39
45
  server_path = URI(Chef::Config[:chef_server_url]).path
40
46
  org = server_path[server_path.rindex('/')+1..-1]
41
47
 
42
- ClcChefServer.client_run(org, config[:node], config[:clusters], @name_args[0], config[:ssh_user], config[:ssh_password])
48
+ ClcChefServer.client_run(
49
+ org,
50
+ config[:node],
51
+ @name_args[0],
52
+ config[:environment],
53
+ config[:ssh_user],
54
+ config[:ssh_password],
55
+ config[:no_converge] ? false : true,
56
+ ui
57
+ )
43
58
  end
44
59
  end
45
60
  end
@@ -4,12 +4,12 @@ require "clc_chef_server/version"
4
4
 
5
5
  module ClcChefServer
6
6
  class << self
7
- TMP_DIR = '/tmp/clc_chef_server/cookbooks'
7
+ TMP_DIR = '/tmp/clc_chef_server'
8
8
 
9
9
  def create_sandbox(organization, ui = nil)
10
10
  repo = Chef::Config.find_chef_repo_path(Dir.pwd)
11
11
  chef_server = URI(Chef::Config[:chef_server_url]).host
12
- Chef::Config[:cookbook_path] = TMP_DIR
12
+ Chef::Config[:cookbook_path] = File.join(TMP_DIR, "cookbooks")
13
13
 
14
14
  %w[clc_library chef_server chef-vault chef-client cron logrotate newrelic].each do |cb|
15
15
  download_cookbook(cb, ui)
@@ -30,26 +30,43 @@ module ClcChefServer
30
30
  shell(command)
31
31
  end
32
32
 
33
- def client_run(organization, node, clusters, environment, ssh_user, ssh_password)
33
+ def client_run(organization, node, clusters, environment, ssh_user, ssh_password, converge, ui)
34
+ require 'chef/knife/ssh'
34
35
  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`
36
+ ui.info "Searching chef server for node #{node}..."
37
+ out = `knife search 'name:#{node}' -a metal.location.ipaddress -c #{Chef::Config[:config_file]}`
38
38
  ip=out[/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/]
39
+
40
+ if ip
41
+ ui.info ip
42
+ else
43
+ ui.error "Unable to find an ip."
44
+ end
45
+
39
46
  if system("ssh-keygen -F #{ip} -f ~/.ssh/known_hosts > /dev/null")
40
47
  system("ssh-keygen -f ~/.ssh/known_hosts -R #{ip} > /dev/null")
41
48
  end
42
49
 
43
50
  command = <<-EOS
44
- knife ssh "name:#{node}" "echo '{
51
+ echo "{
45
52
  \\"provisioner\\": {
46
- \\"clusters\\": \\"#{clusters}\\"
53
+ \\"clusters\\": \\"#{clusters}\\",
54
+ \\"converge\\": #{converge}
47
55
  }
48
- }' | chef-client -E #{environment} \\
56
+ }" | chef-client -E #{environment} \\
49
57
  -l info \\
50
- -j /dev/stdin" -x #{ssh_user} -P #{ssh_password} -c #{knife_path} --attribute metal.location.ipaddress
58
+ -j /dev/stdin
51
59
  EOS
52
- shell(command)
60
+
61
+ Chef::Knife::Ssh.load_deps
62
+ knife = Chef::Knife::Ssh.new
63
+ knife.config[:attribute] = 'ipaddress'
64
+ knife.config[:ssh_user] = ssh_user
65
+ knife.config[:ssh_password_ng] = ssh_password
66
+ knife.config[:config_file] = Chef::Config[:config_file]
67
+ knife.name_args = ["name:#{node}", command]
68
+
69
+ knife.run
53
70
  end
54
71
 
55
72
  private
@@ -1,3 +1,3 @@
1
1
  module ClcChefServer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-clc-chef-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,7 +51,7 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - knife-clc-chef-server.gemspec
54
- - lib/chef/knife/client_run.rb
54
+ - lib/chef/knife/provision.rb
55
55
  - lib/chef/knife/server_sandbox.rb
56
56
  - lib/clc_chef_server.rb
57
57
  - lib/clc_chef_server/version.rb