lib/pvcglue/packages/manager.rb in pvcglue-0.9.3 vs lib/pvcglue/packages/manager.rb in pvcglue-0.9.4

- old
+ new

@@ -46,29 +46,48 @@ def self.get_configuration new.get_configuration end + def self.configuration_exists? + new.configuration_exists? + end + + def configuration_exists? + connection.file_exists?(user_name, ::Pvcglue::Manager.manager_file_name) + end + def get_configuration # if connection.file_exists?(user_name, ::Pvcglue::Manager.manager_file_name) # data = connection.read_from_file(user_name, ::Pvcglue::Manager.manager_file_name) # else # # raise(Thor::Error, "Remote manager file not found: #{::Pvcglue::Manager.manager_file_name}") # raise("Remote manager file not found: #{::Pvcglue::Manager.manager_file_name}") # end data = '' # to use `data` in block - Pvcglue.filter_verbose do - data = connection.read_from_file(user_name, ::Pvcglue::Manager.manager_file_name) + if Pvcglue.command_line_options[:cloud_manager_override] + data = File.read(Pvcglue.command_line_options[:cloud_manager_override]) + else + Pvcglue.filter_verbose do + data = connection.read_from_file(user_name, ::Pvcglue::Manager.manager_file_name) + end end ::Pvcglue.cloud.data = TOML.parse(data) end def self.push_configuration new.push_configuration end def push_configuration + raise('Not supported for local manager') if Pvcglue.command_line_options[:cloud_manager_override] + + test_data = File.read(::Pvcglue.cloud.local_file_name) + TOML.parse(test_data) # At least make sure it's valid TOML + + # TODO: More in-depth validations + connection.upload_file(user_name, ::Pvcglue.cloud.local_file_name, ::Pvcglue::Manager.manager_file_name, nil, nil, '600') git_commit! raise('Error saving configuration') unless working_directory_clean? # TODO: Turn delete back on # File.delete(::Pvcglue.cloud.local_file_name) @@ -90,11 +109,13 @@ def pull_configuration # TODO: Rename to edit_config_start, and create Thor commands to match if connection.file_exists?(user_name, ::Pvcglue::Manager.manager_file_name) data = connection.read_from_file(user_name, ::Pvcglue::Manager.manager_file_name) else - data = "# Pvcglue manager configuration file\n\n" + template = Tilt.new(Pvcglue.template_file_name('pvc_manager.toml.erb')) + data = template.render(self, minion: minion) end + file_name = ::Pvcglue.cloud.local_file_name if File.exist?(file_name) backup_file_name = ::Pvcglue.configuration.versioned_filename(file_name) File.rename(file_name, backup_file_name) Pvcglue.logger.info("Existing local configuration file saved to #{backup_file_name}")