sambot 0.1.98 → 0.1.99

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: 037b2322e89c21b8734016427882cffd24bbd502
4
- data.tar.gz: acc327758471803734325e30c4a3c0f2aa03014f
3
+ metadata.gz: 6e779e1412fd356ebd1c2d95a1e2bba17f95f271
4
+ data.tar.gz: 34d07a2b89b11d01d7b38d8965df70a06fae25ef
5
5
  SHA512:
6
- metadata.gz: e181ac41453f43bdd5d3967882043f70696eb9c1db75452ea47a3fd2f1f711c586e4c977d287b6f48dc30448eb244b43d6c3d7bed2bb6b8672e136bb886484c5
7
- data.tar.gz: dab31035cf135d70b035ad25cfcc806249129cb83dd8335c4d81389d09fd1c711df084fa1541cd4938f029435f06be3a397f297fe6aad746b39c83f246c1843e
6
+ metadata.gz: 43e34ed4faad4c51a78006949492230236899c6461b8ac56813f099663bb41acc8fdfda5c37c4bd2c2d4783ac4849b6542a603dc26b4a7d8a2056d2dabf14b56
7
+ data.tar.gz: 1cf8f3347ab0464e23040bda5757e367f2e50440cc9c75fde66cf79688d45aabe8e8d9f2d22c5a6baf313fad0d209a598cd8f7c754b4f00b8563eaa1e8909147
data/bin/cookbook ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/sambot'
4
+ Sambot::Commands::Cookbook.start
data/bin/report ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/sambot'
4
+ Sambot::Commands::Report.start
data/bin/rundeck ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/sambot'
4
+ Sambot::Commands::Rundeck.start
data/bin/session ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/sambot'
4
+ Sambot::Commands::Session.start
data/bin/workstation ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/sambot'
4
+ Sambot::Commands::Workstation.start
data/lib/sambot.rb CHANGED
@@ -1,4 +1,39 @@
1
+ require_relative 'sambot/application_error'
2
+ require_relative 'sambot/config'
3
+ require_relative 'sambot/ui'
4
+ require_relative 'sambot/runtime'
1
5
  require_relative 'sambot/version'
6
+
7
+ require_relative 'sambot/file_management/template_provider'
8
+ require_relative 'sambot/file_management/file_checker'
9
+
10
+ require_relative 'sambot/chef/kitchen'
11
+ require_relative 'sambot/chef/metadata'
12
+ require_relative 'sambot/chef/cookbook'
13
+ require_relative 'sambot/chef/server'
14
+
15
+ require_relative 'sambot/rackspace/client'
16
+ require_relative 'sambot/rackspace/flavors'
17
+ require_relative 'sambot/rackspace/images'
18
+ require_relative 'sambot/rackspace/instances'
19
+
20
+ require_relative 'sambot/ssh/config_file'
21
+ require_relative 'sambot/ssh/config_section'
22
+ require_relative 'sambot/ssh/parser'
23
+
24
+ require_relative 'sambot/developer_workflow/bastion_host'
25
+ require_relative 'sambot/developer_workflow/dns'
26
+ require_relative 'sambot/developer_workflow/session'
27
+ require_relative 'sambot/developer_workflow/vault'
28
+ require_relative 'sambot/developer_workflow/workstation'
29
+
30
+ require_relative 'sambot/commands/base_command'
31
+ require_relative 'sambot/commands/cookbook'
32
+ require_relative 'sambot/commands/session'
33
+ require_relative 'sambot/commands/workstation'
34
+ require_relative 'sambot/commands/rundeck'
35
+ require_relative 'sambot/commands/report'
36
+
2
37
  require_relative 'sambot/cli'
3
38
 
4
39
  module Sambot
@@ -0,0 +1,60 @@
1
+ require 'ridley'
2
+ require 'json'
3
+
4
+ module Sambot
5
+ module Chef
6
+ class Server
7
+
8
+ SHORT_NAMES = {
9
+ "wsus" => "WSUS",
10
+ "nginx-proxy" => "PRXY",
11
+ "jetstream" => "JTS",
12
+ "task-scheduler" => "TASKS",
13
+ "queue-service" => "QUE",
14
+ "skylight" => "SKY",
15
+ "prometheus" => "PRT",
16
+ "octopus" => "OCTO",
17
+ "vault" => "VAULT",
18
+ "consul" => "CONSUL",
19
+ "rabbitmq" => "RMQ",
20
+ "etcd" => "ETCD",
21
+ "teamcity-agent" => "TCA",
22
+ "teamcity-server" => "TCS",
23
+ "bastion" => "BST",
24
+ "base" => "BASE",
25
+ "grafana" => "MON"
26
+ }
27
+
28
+ def initialize(ridley = nil)
29
+ @ridley = ridley || Ridley.new(
30
+ server_url: "https://chef.brighter.io/organizations/#{ENV['CHEF_ORGANIZATION']}",
31
+ client_name: ENV['CHEF_CLIENT_NAME'],
32
+ client_key: ENV['CHEF_CLIENT_KEY'],
33
+ proxy: ENV['FIXIE_URL']
34
+ )
35
+ end
36
+
37
+ def cookbooks
38
+ @cookbooks ||= @ridley.cookbook.all.select {|x| x =~ /as-/}.keys.sort
39
+ end
40
+
41
+ def roles
42
+ cookbooks.select {|x| x =~ /role/}
43
+ end
44
+
45
+ def find_role_name(cookbook)
46
+ naive_name = cookbook.gsub(/as-role-/, "").gsub(/as-app-role-/, "")
47
+ if SHORT_NAMES.key?(naive_name)
48
+ SHORT_NAMES[naive_name]
49
+ else
50
+ raise "Could not generate an instance name"
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+ #Find out what's happening on the security front
60
+ #Summarize conversation with Daven & take
data/lib/sambot/cli.rb CHANGED
@@ -1,24 +1,4 @@
1
1
  require 'thor'
2
- require_relative 'application_error'
3
- require_relative 'config'
4
- require_relative 'ui'
5
- require_relative 'runtime'
6
- require_relative 'file_management/template_provider'
7
- require_relative 'file_management/file_checker'
8
- require_relative 'chef/kitchen'
9
- require_relative 'chef/metadata'
10
- require_relative 'chef/cookbook'
11
- require_relative 'ssh/config_file'
12
- require_relative 'ssh/config_section'
13
- require_relative 'ssh/parser'
14
- require_relative 'developer_workflow/bastion_host'
15
- require_relative 'developer_workflow/dns'
16
- require_relative 'developer_workflow/session'
17
- require_relative 'developer_workflow/vault'
18
- require_relative 'developer_workflow/workstation'
19
- require_relative 'commands/cookbook'
20
- require_relative 'commands/session'
21
- require_relative 'commands/workstation'
22
2
 
23
3
  module Sambot
24
4
  class CLI < Thor
@@ -0,0 +1,18 @@
1
+ require 'thor/hollaback'
2
+
3
+ module Sambot
4
+ module Commands
5
+
6
+ class BaseCommand < Thor
7
+
8
+ before :check_version
9
+
10
+ no_commands do
11
+ def check_version
12
+ Runtime.ensure_latest
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,10 +1,12 @@
1
+ require 'thor'
2
+
1
3
  module Sambot
2
4
  module Commands
3
5
 
4
6
  ESSENTIAL_FILES = ['.config.yml', 'recipes', 'README.md'].freeze
5
7
  GENERATED_FILES = ['teamcity.sh.erb', 'chefignore', 'Berksfile', '.rubocop.yml', '.gitignore'].freeze
6
8
 
7
- class Cookbook < Thor
9
+ class Cookbook < BaseCommand
8
10
 
9
11
  GUIDE =
10
12
  {
@@ -42,7 +44,6 @@ module Sambot
42
44
  desc 'clean', GUIDE[:clean][:SHORT_DESC]
43
45
  long_desc GUIDE[:clean][:LONG_DESC]
44
46
  def clean
45
- Runtime.ensure_latest
46
47
  Chef::Cookbook.clean(GENERATED_FILES - ['.gitignore'])
47
48
  rescue ApplicationError => e
48
49
  error(e.message)
@@ -51,7 +52,6 @@ module Sambot
51
52
  desc 'build', GUIDE[:clean][:SHORT_DESC]
52
53
  long_desc GUIDE[:clean][:LONG_DESC]
53
54
  def build
54
- Runtime.ensure_latest
55
55
  Chef::Cookbook.build(ESSENTIAL_FILES, GENERATED_FILES)
56
56
  rescue ApplicationError => e
57
57
  error(e.message)
@@ -60,7 +60,6 @@ module Sambot
60
60
  desc 'generate', GUIDE[:generate][:SHORT_DESC]
61
61
  long_desc GUIDE[:generate][:LONG_DESC]
62
62
  def generate()
63
- Runtime.ensure_latest
64
63
  name = ask(' What is the name of this cookbook?')
65
64
  description = ask(' What does this cookbook do?')
66
65
  platforms = ask(' What operating system will this cookbook run on?', :limited_to => ['windows', 'centos', 'both'])
@@ -74,7 +73,6 @@ module Sambot
74
73
  desc 'version', GUIDE[:version][:SHORT_DESC]
75
74
  long_desc GUIDE[:version][:LONG_DESC]
76
75
  def version()
77
- Runtime.ensure_latest
78
76
  result = Config.new.read
79
77
  puts "##teamcity[buildNumber '#{result['version'].to_s}']"
80
78
  rescue ApplicationError => e
File without changes
@@ -0,0 +1,39 @@
1
+ require_relative 'flavors'
2
+ require_relative 'instances'
3
+ require_relative 'images'
4
+
5
+ module Sambot
6
+ module Rackspace
7
+ class Client
8
+
9
+ RACKSPACE_ACCOUNTS = [
10
+ { api_key: -> {ENV['ADVERTISING1_API_KEY']}, id: 'advertising1' },
11
+ { api_key: ->{ ENV['SAMTAYLOR_API_KEY']}, id: 'samtaylor' }
12
+ ]
13
+
14
+ def initialize(api_key = RACKSPACE_ACCOUNTS[0][:api_key], account_id = RACKSPACE_ACCOUNTS[0][:id])
15
+ options = {
16
+ :provider => 'Rackspace',
17
+ :rackspace_api_key => api_key.call,
18
+ :rackspace_username => account_id,
19
+ :rackspace_region => 'LON'
20
+ }
21
+ options[:connection_options] = {:proxy => ENV['FIXIE_URL']} if ENV['FIXIE_URL']
22
+ Fog::Compute.new(options)
23
+ end
24
+
25
+ def instances
26
+ @instances ||= Instances.new(self)
27
+ end
28
+
29
+ def flavors
30
+ @flavors ||= Flavors.new(self)
31
+ end
32
+
33
+ def images
34
+ @images ||= Images.new(self)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module Sambot
2
+ module Rackspace
3
+ class Flavors
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def all()
10
+ @client.flavors.all.map {|flavor| {name: flavor.name, value: flavor.id}}.compact
11
+ end
12
+
13
+ def available
14
+ all.find_all {|x| x[:name] =~ /Standard/}
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Sambot
2
+ module Rackspace
3
+ class Images
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def all
10
+ @client.images.all.map {|image| {name: image.name, value: image.id}}.compact
11
+ end
12
+
13
+ def available
14
+ all.find_all {|x| x[:name] =~ /AS/}
15
+ end
16
+
17
+ def find_platform_by_image_id(id)
18
+ available_images = all
19
+ image = available_images.find {|x| x[:value] == id}
20
+ image[:name] =~ /Linux/ ? "L" : "W"
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,84 @@
1
+ module Sambot
2
+ module Rackspace
3
+ class Instances
4
+
5
+ def all(extended = false)
6
+ result = []
7
+ RACKSPACE_ACCOUNTS.each do |account|
8
+ api = Client.new(account[:api_key], account[:id])
9
+ api.servers.all.map do |server|
10
+ name = server.name
11
+ ip = server.addresses["private"].last["addr"]
12
+ if extended
13
+ result << { name: name, value: ip, id: server.id }
14
+ else
15
+ result << { name: name, value: ip}
16
+ end
17
+ end
18
+ end
19
+ result.flatten
20
+ end
21
+
22
+ def belonging_to(team)
23
+ results = self.all
24
+ team_initials = team.downcase
25
+ results.select do |instance|
26
+ instance_name = instance[:name].downcase
27
+ if team_initials == "nw"
28
+ instance_name.start_with?(team_initials) || instance_name.start_with?("dev")
29
+ else
30
+ instance_name.start_with?(team_initials)
31
+ end
32
+ end
33
+ end
34
+
35
+ def find_next_index(team, role)
36
+ raise "No team name was provided. It should be the short form of the team i.e. NW or AVG." unless team
37
+ raise "No cookbook name was provided. It needs to be a role cookbook." unless role
38
+ team_instances = self.all.find_all {|x| x[:name] =~ /#{team}-#{role}/i}
39
+ return "01" if team_instances.size < 1
40
+ similar_instances = team_instances.map {|x| x[:name].upcase.gsub("#{team}-#{role}".upcase, "").gsub(/^\-/, "")}
41
+ current_index = similar_instances.map {|x| x.match(/(.+)-(.+)/)[1].to_i}.sort[-1] + 1
42
+ current_index.to_s.rjust(2, '0')
43
+ end
44
+
45
+ def as_rundeck_nodes
46
+ result = []
47
+ images = Images.all
48
+ flavors = Flavors.all
49
+ RACKSPACE_ACCOUNTS.each do |account|
50
+ api = Rackspace.connect(account[:api_key], account[:id])
51
+ api.servers.all.map do |server|
52
+ flavor = flavors.detect {|x| x[:value] == server.flavor_id}
53
+ image = images.detect {|x| x[:value] == server.image_id}
54
+ image_name = image ? image[:name] : 'unknown'
55
+ team = Teams.find_from_instance_name(server.name)
56
+ result << {
57
+ name: server.name,
58
+ team: team ? Teams.all.find {|x| x[:value] == team}[:name] : "Night Watch",
59
+ os: self.find_os(server.name),
60
+ hostname: server.addresses["private"].last["addr"],
61
+ created: server.created,
62
+ state: server.state,
63
+ role: 'none',
64
+ flavor: flavor ? flavor[:name] : 'unknown',
65
+ image: image_name
66
+ }
67
+ end
68
+ end
69
+ result.flatten
70
+ end
71
+
72
+ def by_name(name)
73
+ instances = self.all(true)
74
+ x = instances.select {|x| x[:name].upcase == name.upcase}
75
+ x.size == 1 ? x[0][:id] : nil
76
+ end
77
+
78
+ def find_os(name)
79
+ name =~ /\-L\d+$/ ? "Linux" : "Windows"
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -1,3 +1,3 @@
1
1
  module Sambot
2
- VERSION = '0.1.98'.freeze
2
+ VERSION = '0.1.99'.freeze
3
3
  end
data/sambot.gemspec CHANGED
@@ -16,14 +16,17 @@ Gem::Specification.new do |spec|
16
16
  f.match(%r{^(test|spec|features)/})
17
17
  end
18
18
  spec.bindir = 'bin'
19
- spec.executables = 'sambot'
19
+ spec.executables = ['sambot', 'cookbook', 'workstation', 'session', 'rundeck']
20
20
  spec.require_paths = ['lib']
21
21
 
22
+ spec.add_dependency 'thor-hollaback'
22
23
  spec.add_dependency 'git'
23
24
  spec.add_dependency 'process_exists'
24
25
  spec.add_dependency 'climate_control'
25
26
  spec.add_dependency 'vault'
26
27
  spec.add_dependency 'hosts'
28
+ spec.add_dependency 'fog'
29
+ spec.add_dependency 'ridley'
27
30
  spec.add_dependency 'chef', '~> 12.18'
28
31
  spec.add_dependency 'thor', '~> 0.19'
29
32
  spec.add_dependency 'erubis', '~> 2.7', '>= 2.7.0'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sambot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.98
4
+ version: 0.1.99
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Kouame
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor-hollaback
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: git
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,34 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fog
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ridley
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: chef
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -272,6 +314,10 @@ email:
272
314
  - olivier.kouame@gmail.com
273
315
  executables:
274
316
  - sambot
317
+ - cookbook
318
+ - workstation
319
+ - session
320
+ - rundeck
275
321
  extensions: []
276
322
  extra_rdoc_files: []
277
323
  files:
@@ -282,17 +328,24 @@ files:
282
328
  - Gemfile
283
329
  - README.md
284
330
  - Rakefile
285
- - bin/console
331
+ - bin/cookbook
332
+ - bin/report
333
+ - bin/rundeck
286
334
  - bin/sambot
335
+ - bin/session
287
336
  - bin/setup
337
+ - bin/workstation
288
338
  - lib/sambot.rb
289
339
  - lib/sambot/application_error.rb
290
340
  - lib/sambot/chef/cookbook.rb
291
341
  - lib/sambot/chef/kitchen.rb
292
342
  - lib/sambot/chef/metadata.rb
343
+ - lib/sambot/chef/server.rb
293
344
  - lib/sambot/cli.rb
345
+ - lib/sambot/commands/base_command.rb
294
346
  - lib/sambot/commands/cookbook.rb
295
347
  - lib/sambot/commands/report.rb
348
+ - lib/sambot/commands/rundeck.rb
296
349
  - lib/sambot/commands/session.rb
297
350
  - lib/sambot/commands/workstation.rb
298
351
  - lib/sambot/config.rb
@@ -303,6 +356,10 @@ files:
303
356
  - lib/sambot/developer_workflow/workstation.rb
304
357
  - lib/sambot/file_management/file_checker.rb
305
358
  - lib/sambot/file_management/template_provider.rb
359
+ - lib/sambot/rackspace/client.rb
360
+ - lib/sambot/rackspace/flavors.rb
361
+ - lib/sambot/rackspace/images.rb
362
+ - lib/sambot/rackspace/instances.rb
306
363
  - lib/sambot/reports/consistency_report.rb
307
364
  - lib/sambot/runtime.rb
308
365
  - lib/sambot/ssh/config_file.rb
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'sambot'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require 'pry'
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)