pe_info 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f1d46674fe37394b392fc487bba0b02f389622f
4
- data.tar.gz: 62dbf3e448126727560f1dff41f6de937b926025
3
+ metadata.gz: 4489b5366f96844f0c511030e49986133d224e7e
4
+ data.tar.gz: 2ab2613f979ddaeb6c8030f72cd0503bbe68c952
5
5
  SHA512:
6
- metadata.gz: 3223cb7cc69bd9add32c8a85c60f86cd0d37689d18502073e782b34ae999707e6d78bd36dc35e19870e23418e56d9d2070718741794a7968ba34163067252adc
7
- data.tar.gz: 2d9798a5d04ad530d248be7c132596d892da99dcf112091d64b247651c6a5083ec133a9bf8453e3708811f1b1b45efb875b845d81598f39be0e672cc0db1d9f8
6
+ metadata.gz: e65248cebe0cd9c7eed9c49b025364373b3fc6d0116dbe66efbcc7d0edc7e1b0ba0a8c2659bd33dac0ba95fa5347038f6d0670c14098a834e2fff34126cf53d5
7
+ data.tar.gz: 2a6e516f1e91b9654d2153921fd958c7e119f858933e43848bd95e70cd6f2640ce49979a3106bc58d2cee46331afe97608a3d8d568f886063760af1dc05b85f3
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.gem
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
+ [![Build Status](https://travis-ci.org/GeoffWilliams/pe_info.svg?branch=master)](https://travis-ci.org/GeoffWilliams/pe_info)
1
2
  # PeInfo
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pe_info`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ This is a simple library for figuring out things we need to know about Puppet
5
+ Enterprise, such as where to upload agent installers and what the agent version
6
+ number is.
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
8
+ This is done by either munging supplied version arguments or in the case of
9
+ agent versions, looking inside of an installation media tarball.
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,7 +26,42 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ### Uploading agent installers
30
+
31
+ Lets say you have an agent installer tarball you previously downloaded:
32
+ ```
33
+ ...
34
+ 38M /Users/geoff/agent_installers/2016.5.1/puppet-agent-sles-10-x86_64.tar.gz
35
+ 25M /Users/geoff/agent_installers/2016.5.1/puppet-agent-sles-11-i386.tar.gz
36
+ 33M /Users/geoff/agent_installers/2016.5.1/puppet-agent-sles-11-s390x.tar.gz
37
+ ...
38
+ ```
39
+
40
+ And you would like to know where it should be uploaded on a server you just
41
+ installed with PE 2016.5.1 from `/Users/geoff/Downloads/puppet-enterprise-2016.5.1-el-7-x86_64.tar.gz`:
42
+
43
+ ```ruby
44
+ require 'pe_info'
45
+ tarball = '/Users/geoff/Downloads/puppet-enterprise-2016.5.1-el-7-x86_64.tar.gz'
46
+ pe_version, agent_version = PeInfo::Tarball::inspect(tarball)
47
+ if pe_version and agent_version
48
+ upload_path = PeInfo::System::agent_installer_upload_path(
49
+ pe_version,
50
+ agent_version,
51
+ repo_file
52
+ )
53
+
54
+ if upload_path
55
+ # do something with upload_path
56
+ else
57
+ # unparsable agent_version
58
+ end
59
+ else
60
+ # install tarball missing or invalid
61
+ end
62
+ ```
63
+
64
+ Now you know that the agent installers tarball belongs at `upload_path`. If you upload the file to this location on a PE master, it will remove the need to head out to the internet and download the file manually.
26
65
 
27
66
  ## Development
28
67
 
@@ -32,5 +71,30 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
71
 
33
72
  ## Contributing
34
73
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pe_info.
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/GeoffWilliams/pe_info.
75
+
76
+ Please ensure tests are passing before and after any contributions and please update tests as required for new functionality and bugfixes:
77
+
78
+ ```
79
+ bundle install
80
+ bundle exec rake spec
81
+ ```
82
+
83
+ ### Creating mock PE tarballs
84
+ To create a PE tarball identical to a release but with every file truncated to zero bytes:
85
+
86
+ ```shell
87
+ mkdir tmp
88
+ cd tmp
89
+ tar zxvf PE_UPSTREAM_TARBALL
90
+ cd puppet-enterprise-*
91
+ find . -type f -exec truncate -s 0 {} \;
92
+ cd ..
93
+ tar zcvf MOCK_PE_UPSTREAM_TARBALL puppet-enterprise-*
94
+ ```
95
+
96
+ Once created, the tarball can be moved to spec/fixtures/tarballs and the tmp directory can be removed
36
97
 
98
+ ## Support
99
+ * This is experimental software, use at own risk!
100
+ * This software is not supported by Puppet, Inc.
@@ -1,3 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2016 Geoff Williams for Puppet Inc.
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.
1
16
  module PeInfo
2
17
  module System
3
18
  AGENT_UPLOAD_PATH_NORMAL = '/opt/puppetlabs/server/data/staging'
@@ -16,7 +31,7 @@ module PeInfo
16
31
  "/#{AGENT_UPLOAD_PATH_WINDOWS}/#{pe_version}/windows-x86_64-#{agent_version}"
17
32
  end
18
33
 
19
- def self.upload_path(pe_version, agent_version, installer)
34
+ def self.agent_installer_upload_path(pe_version, agent_version, installer)
20
35
  if installer =~ /puppet-agent-x64.msi/
21
36
  path = agent_installer_upload_path_windows_x64(pe_version, agent_version)
22
37
  elsif installer =~ /puppet-agent-x86.msi/
@@ -1,25 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2016 Geoff Williams for Puppet Inc.
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.
1
16
  require "pe_info/version"
2
17
 
3
18
  module PeInfo
4
19
  module Tarball
20
+ def self.tar
21
+ begin
22
+ tar_version = %x(tar --version)
23
+ if tar_version =~ /GNU/
24
+ tar = 'tar --wildcards '
25
+ else
26
+ tar = 'tar'
27
+ end
28
+ rescue Errno::ENOENT
29
+ raise "please install tar and make sure its in your PATH"
30
+ end
31
+
32
+ tar
33
+ end
34
+
5
35
  def self.is_pe_tarball(tarball)
6
- tarball =~ /puppet-enterprise-\d{4}\.\d+\.\d+.*\.tar\.gz/
36
+ # =~ returns nil if no matches or position of first match so we must
37
+ # convert its result to a boolean for easy use
38
+ tarball =~ /puppet-enterprise-\d{4}\.\d+\.\d+.*\.tar\.gz/ ? true : false
7
39
  end
8
40
 
9
41
  def self.pe_version(tarball)
10
- pe_version = tarball.match(/puppet-enterprise-(\d{4}\.\d+\.\d+)/).captures.first
42
+ matches = tarball.match(/puppet-enterprise-(\d{4}\.\d+\.\d+)/)
43
+ pe_version = matches ? matches.captures.first : false
11
44
 
12
45
  pe_version
13
46
  end
14
47
 
15
48
  def self.agent_version(tarball)
16
- agent_package = %x(tar ztf #{tarball} '**/puppet-agent*')
17
- agent_version = agent_package.match(/puppet-agent-(\d+\.\d+\.\d+)/).captures.first
49
+ agent_package = %x(#{tar} -ztf #{tarball} '*/puppet-agent*')
50
+ matches = agent_package.match(/puppet-agent-(\d+\.\d+\.\d+)/)
51
+ agent_version = matches ? matches.captures.first : false
18
52
 
19
53
  agent_version
20
54
  end
21
55
 
22
56
  def self.inspect(tarball)
57
+ pe_version = false
58
+ agent_version = false
59
+
23
60
  if is_pe_tarball(tarball)
24
61
  if File.exists?(tarball)
25
62
 
@@ -29,10 +66,10 @@ module PeInfo
29
66
  # look for the agent version
30
67
  agent_version = agent_version(tarball)
31
68
  else
32
- raise "File not found: #{tarball}"
69
+ PeInfo.logger.debug "File not found: #{tarball}"
33
70
  end
34
71
  else
35
- raise "Not a puppet install tarball: #{tarball}"
72
+ PeInfo.logger.debug "Not a puppet install tarball: #{tarball}"
36
73
  end
37
74
  return pe_version, agent_version
38
75
  end
@@ -1,3 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2016 Geoff Williams for Puppet Inc.
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.
1
16
  module PeInfo
2
- VERSION = "0.1.4"
17
+ VERSION = "0.1.6"
3
18
  end
data/lib/pe_info.rb CHANGED
@@ -1,3 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2016 Geoff Williams for Puppet Inc.
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
+ require 'logger'
17
+
1
18
  module PeInfo
2
19
 
20
+ # lazy-init logger to be a regular ruby logger instance. If you want
21
+ # something else, call logger= before doing things that generate logging
22
+ # ...based on http://stackoverflow.com/a/6768164
23
+ def self.logger
24
+ @logger ||= Logger.new(STDOUT)
25
+ end
26
+
27
+ def self.logger=(logger)
28
+ @logger = logger
29
+ end
30
+
3
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pe_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler