Class: Chef::Knife::EnvironmentTarDownload

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/environment_tar_download.rb

Constant Summary collapse

@@DEFAULT_ENVIRONMENT =
"_default"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.download_environments(tar_file) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/knife/environment_tar_download.rb', line 29

def self.download_environments(tar_file)
  dir = tar_file.environments_path
  Chef::Environment.list.each do |component_name, url|
    if component_name != @@DEFAULT_ENVIRONMENT
      Chef::Log.info("Backing up environment #{component_name}")
      component_obj = Chef::Environment.load(component_name)
      File.open(File.join(dir, "#{component_name}.json"), "w") do |component_file|
        component_file.print(component_obj.to_json)
      end
    end
  end
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chef/knife/environment_tar_download.rb', line 15

def run
  #Get Arguments
  if @name_args.size != 1
    ui.info("Please specify a tar path")
    show_usage
    exit 1
  end
  
  tar_file = Chef::TarFile.new(@name_args.first, true)
  EnvironmentTarDownload.download_environments tar_file
  tar_file.save
  
end