lib/chef/knife/topo_cookbook_upload.rb in knife-topo-1.1.2 vs lib/chef/knife/topo_cookbook_upload.rb in knife-topo-2.0.1
- old
+ new
@@ -15,73 +15,59 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/knife'
-require_relative 'topology_helper'
+require 'chef/knife/topo/loader'
+require 'chef/knife/cookbook_upload' unless defined? Chef::Knife::CookbookUpload
-## only require if not already defined (to prevent warning about already initialized constants)
-require 'chef/knife/cookbook_upload' if !defined? Chef::Knife::CookbookUpload
+module KnifeTopo
+ # knife topo cookbook upload
+ class TopoCookbookUpload < Chef::Knife
+ deps do
+ require 'chef/knife/topo/processor'
+ end
-class Chef
- class Knife
- class TopoCookbookUpload < Chef::Knife
-
- deps do
- Chef::Knife::CookbookUpload.load_deps
- end
+ banner 'knife topo cookbook upload TOPOLOGY (options)'
- banner "knife topo cookbook upload [ TOPOLOGY ] (options)"
+ option(
+ :data_bag,
+ short: '-D DATA_BAG',
+ long: '--data-bag DATA_BAG',
+ description: 'The data bag the topologies are stored in'
+ )
- option :data_bag,
- :short => '-D DATA_BAG',
- :long => "--data-bag DATA_BAG",
- :description => "The data bag the topologies are stored in"
+ # Make called command options available
+ self.options = (Chef::Knife::CookbookUpload.options).merge(
+ TopoCookbookUpload.options)
- # Make called command options available
- self.options = (Chef::Knife::CookbookUpload.options).merge(self.options)
+ include KnifeTopo::Loader
- def initialize (args)
- super
- @topo_upload_args = initialize_cmd_args(args, [ 'cookbook', 'upload' ])
+ def initialize(args)
+ super
+ @args = args
- # All called commands need to accept union of options
- Chef::Knife::CookbookUpload.options = options
- end
-
- def run
- if !@name_args[0]
- show_usage
- ui.fatal("You must specify the name of a topology")
- exit 1
- end
+ # All called commands need to accept union of options
+ Chef::Knife::CookbookUpload.options = options
+ end
- bag_name = topo_bag_name(config[:data_bag])
- topo_name = @name_args[0]
+ def run
+ validate_args
- # Load the topology data
- unless topo = load_from_file(bag_name, topo_name )
- ui.fatal("Topology file #{topologies_path}/#{bag_name}/#{topo_name}.json not found - use 'knife topo import' first")
- exit(1)
- end
-
- # Run cookbook upload command on the topology cookbooks
- cookbook_names = []
- if topo['cookbook_attributes'] && topo['cookbook_attributes'].length > 0
- argPos = 2
- topo['cookbook_attributes'].each do |entry|
- cookbook_name = entry['cookbook']
- @topo_upload_args[argPos] = cookbook_name unless cookbook_names.include?(cookbook_name)
- cookbook_names << cookbook_name
- argPos += 1
- end
- run_cmd(Chef::Knife::CookbookUpload, @topo_upload_args)
- else
- ui.info("No cookbooks found for topology #{display_name(topo)}")
- end
- end
+ # Load the topology data
+ @topo = load_local_topo_or_exit(@topo_name)
- include Chef::Knife::TopologyHelper
+ # Run cookbook upload command on the topology cookbook
+ @processor = KnifeTopo::Processor.for_topo(@topo)
+ @processor.upload_artifacts('cmd' => self, 'cmd_args' => @args)
+ end
+ def validate_args
+ unless @name_args[0]
+ show_usage
+ ui.fatal('You must specify the name of a topology')
+ exit 1
+ end
+ @topo_name = @name_args[0]
end
end
end