Class: Puppetserver::Ca::Action::Migrate
- Inherits:
-
Object
- Object
- Puppetserver::Ca::Action::Migrate
- Includes:
- Utils
- Defined in:
- lib/puppetserver/ca/action/migrate.rb
Constant Summary collapse
- PUPPETSERVER_CA_DIR =
Puppetserver::Ca::Utils::Config.new_default_cadir
- SUMMARY =
"Migrate the existing CA directory to #{PUPPETSERVER_CA_DIR}"- BANNER =
"Usage:\n puppetserver ca migrate [--help]\n puppetserver ca migrate [--config PATH]\n\nDescription:\n Migrate an existing CA directory to \#{PUPPETSERVER_CA_DIR}. This is for\n upgrading from Puppet Platform 6.x to Puppet 7. Uses the default puppet.conf\n in your installation, or use a different config by supplying the `--config` flag.\n\nOptions:\n"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(logger) ⇒ Migrate
constructor
A new instance of Migrate.
- #migrate(old_cadir, new_cadir = PUPPETSERVER_CA_DIR) ⇒ Object
- #parse(args) ⇒ Object
- #run(input) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Migrate
27 28 29 |
# File 'lib/puppetserver/ca/action/migrate.rb', line 27 def initialize(logger) @logger = logger end |
Class Method Details
.parser(parsed = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/puppetserver/ca/action/migrate.rb', line 82 def self.parser(parsed = {}) OptionParser.new do |opts| opts. = BANNER opts.on('--help', 'Display this command-specific help output') do |help| parsed['help'] = true end opts.on('--config CONF', 'Path to puppet.conf') do |conf| parsed['config'] = conf end end end |
Instance Method Details
#migrate(old_cadir, new_cadir = PUPPETSERVER_CA_DIR) ⇒ Object
68 69 70 71 |
# File 'lib/puppetserver/ca/action/migrate.rb', line 68 def migrate(old_cadir, new_cadir=PUPPETSERVER_CA_DIR) FileUtils.mv(old_cadir, new_cadir) FileSystem.forcibly_symlink(new_cadir, old_cadir) end |
#parse(args) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/puppetserver/ca/action/migrate.rb', line 73 def parse(args) results = {} parser = self.class.parser(results) errors = CliParsing.parse_with_errors(parser, args) errors_were_handled = Errors.handle_with_usage(@logger, errors, parser.help) exit_code = errors_were_handled ? 1 : nil return results, exit_code end |
#run(input) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppetserver/ca/action/migrate.rb', line 31 def run(input) config_path = input['config'] puppet = Config::Puppet.new(config_path) puppet.load(logger: @logger, ca_dir_warn: false) return 1 if HttpClient.check_server_online(puppet.settings, @logger) errors = FileSystem.check_for_existing_files(PUPPETSERVER_CA_DIR) if !errors.empty? instructions = "Migration will not overwrite the directory at \#{PUPPETSERVER_CA_DIR}. Have you already\nrun this migration tool? Is this a puppet 7 installation? It is likely that you have\nalready successfully run the migration or do not need to run it.\n" errors << instructions Errors.handle_with_usage(@logger, errors) return 1 end current_cadir = puppet.settings[:cadir] if FileSystem.check_for_existing_files(current_cadir).empty? = "No CA dir found at \#{current_cadir}. Please check the configured cadir setting in your\npuppet.conf file and verify its contents.\n" Errors.handle_with_usage(@logger, []) return 1 end migrate(current_cadir) @logger.inform "CA dir successfully migrated to \#{PUPPETSERVER_CA_DIR}. Symlink placed at \#{current_cadir}\nfor backwards compatibility. The puppetserver can be safely restarted now.\n" return 0 end |