Class: KnifeTopo::TopoImport

Inherits:
Chef::Knife
  • Object
show all
Includes:
CommandHelper, Loader
Defined in:
lib/chef/knife/topo_import.rb

Overview

knife topo import

Instance Attribute Summary

Attributes included from Loader

#loader, #ui

Instance Method Summary collapse

Methods included from Loader

#auto_detect_format, #check_file, #create_topo_bag, #get_local_topo_path, #list_topo_bag, #load_local_topo_or_exit, #load_node_data, #load_topo_from_file_or_exit, #load_topo_from_server, #load_topo_from_server_or_exit, #priority_attrs, #topo_bag_name, #topologies_path

Methods included from CommandHelper

#check_chef_env, #initialize_cmd_args, #most_common, #resource_exists?, #run_cmd

Constructor Details

#initialize(args) ⇒ TopoImport

Returns a new instance of TopoImport.



52
53
54
55
56
# File 'lib/chef/knife/topo_import.rb', line 52

def initialize(args)
  super
  @args = args
  @topo_file = @name_args[0] || 'topology.json'
end

Instance Method Details

#create_topo_bag_dirObject



65
66
67
68
69
# File 'lib/chef/knife/topo_import.rb', line 65

def create_topo_bag_dir
  # make sure the topology bag directory exists
  path = File.join(topologies_path, topo_bag_name)
  FileUtils.mkdir_p(path)
end

#do_create_artifactsObject



87
88
89
90
91
92
# File 'lib/chef/knife/topo_import.rb', line 87

def do_create_artifacts
  @processor.generate_artifacts(
    'cmd_args' => @args,
    'cmd' => self
  )
end

#import_topoObject



71
72
73
74
75
76
# File 'lib/chef/knife/topo_import.rb', line 71

def import_topo
  write_topo_to_file
  do_create_artifacts

  ui.info "Imported topology: #{@topo.display_info}"
end

#runObject



58
59
60
61
62
63
# File 'lib/chef/knife/topo_import.rb', line 58

def run
  @topo = load_topo_from_file_or_exit(@topo_file, config[:input_format])
  @processor = KnifeTopo::Processor.for_topo(@topo)
  create_topo_bag_dir
  import_topo
end

#write_topo_to_fileObject



78
79
80
81
82
83
84
85
# File 'lib/chef/knife/topo_import.rb', line 78

def write_topo_to_file
  path = File.join(topologies_path, topo_bag_name, @topo['name'] + '.json')
  File.open(path, 'w') do |f|
    f.write(Chef::JSONCompat.to_json_pretty(@topo.raw_data))
    f.close
    ui.info "Created topology data bag: #{path}"
  end
end