module Dopv::Cli
Public Class Methods
command_add(base)
click to toggle source
# File lib/dopv/cli/command_add.rb, line 4 def self.command_add(base) base.class_eval do desc 'Add a new plan file to the plan store' arg_name 'plan_file' command :add do |c| c.desc 'Update the plan if it already exists in plan store' c.switch [:update, :u], :negatable => false c.action do |global_options, options, args| help_now!('Add takes exactly one argument, a plan file.') if args.empty? || args.length != 1 plan_file = args[0] exit_now!("The plan file #{plan_file} must be a readable file.") unless File.file?(plan_file) && File.readable?(plan_file) begin puts Dopv.add(plan_file) rescue DopCommon::PlanExistsError => e if options[:update] puts Dopv.update_plan(plan_file, {}) else raise "#{e}, please use 'dopv update' first, or use -u|--update flag to add this plan forcibly." end end end end end end
command_export(base)
click to toggle source
# File lib/dopv/cli/command_export.rb, line 4 def self.command_export(base) base.class_eval do desc 'Export the internal data disks state into a local file' arg_name 'plan_name data_disks_file' command :export do |c| c.action do |global_options, options, args| help_now!('Export takes exactly two arguments, plan name and data disks file.') if args.empty? || args.length != 2 plan_name, data_disks_file = args data_disks_dir = File.dirname(data_disks_file) exit_now!("The #{data_disks_dir} must be a directory writable by the process.") unless File.directory?(data_disks_dir) && File.writable?(data_disks_dir) Dopv.export_state_file(plan_name, data_disks_file) end end end end
command_import(base)
click to toggle source
# File lib/dopv/cli/command_import.rb, line 4 def self.command_import(base) base.class_eval do desc 'Import data disks from a file into internal state store of the given plan' arg_name 'plan_name data_disks_file' command :import do |c| c.desc 'Force plan import' c.switch [:f, :force], :negatable => false c.action do |global_options, options, args| help_now!('Import takes exactly two arguments, a plan name and data disks file.') if args.empty? || args.length != 2 plan_name, data_disks_file = args exit_now!("The #{data_disks_file} must be a readable file.") unless File.file?(data_disks_file) && File.readable?(data_disks_file) if !Dopv.export_state(plan_name).empty? && !options[:force] exit_now!("The internal plan's state is not empty, please use the '-f|--force' flag to overwrite.") end Dopv.import_state_file(plan_name, data_disks_file) end end end end
command_list(base)
click to toggle source
# File lib/dopv/cli/command_list.rb, line 4 def self.command_list(base) base.class_eval do desc 'List plans stored in the plan store' command :list do |c| c.action do |global_options,options,args| puts Dopv.list end end end end
command_remove(base)
click to toggle source
# File lib/dopv/cli/command_remove.rb, line 4 def self.command_remove(base) base.class_eval do desc 'Remove existing plan from the plan store' arg_name 'plan_name' command :remove do |c| c.desc 'Keep the DOPi state file' c.switch [:k, :keep_dopi_state], :negatable => false c.desc 'Remove the DOPv state file (THIS REMOVES THE DISK STATE!)' c.switch [:r, :remove_dopv_state], :negatable => false c.action do |global_options, options, args| help_now!('Remove take exactly one argument, a plan name.') if args.empty? || args.length != 1 plan_name = args[0] Dopv.remove(plan_name, !options[:keep_dopi_state], options[:remove_dopv_state]) end end end end
command_run(base, action)
click to toggle source
# File lib/dopv/cli/command_run.rb, line 4 def self.command_run(base, action) base.class_eval do desc "#{action.capitalize} a plan." arg_name 'plan_name' command action do |c| if action == :undeploy c.desc 'Remove data disks from the state and cloud provider.' c.switch [:rmdisk, :r], :default_value => false end DopCommon::Cli.node_select_options(c) c.action do |global_options, options, args| options[:run_for_nodes] = DopCommon::Cli.parse_node_select_options(options) help_now!("#{action.capitalize} takes exactly one argument, a plan name.") if args.empty? || args.length > 1 plan_name = args[0] begin case action when :deploy then Dopv.deploy(plan_name, options) when :undeploy then Dopv.undeploy(plan_name, options) when :refresh then Dopv.refresh(plan_name, options) end end end end end end
command_update(base)
click to toggle source
# File lib/dopv/cli/command_update.rb, line 4 def self.command_update(base) base.class_eval do desc 'Update the plan and/or the plan state for a given plan yaml or plan name.' arg_name 'plan_file_or_name' command :update do |c| c.desc 'Remove the existing disk information and start with a clean state.' c.switch [:clear, :c], :default_value => false c.desc 'Ignore the update and set the state version to the latest version.' c.switch [:ignore, :i], :default_value => false c.action do |global_options, options, args| help_now!('Update takes exactly one argument, the plan name or file.') if args.empty? || args.length != 1 plan = args[0] if Dopv.list.include?(plan) Dopv.update_state(plan, options) elsif File.file?(plan) && File.readable?(plan) Dopv.update_plan(plan, options) else exit_now!("No such plan '#{plan}' in the store or the plan file doesn't exist or is unreadable.") end end end end end
command_validate(base)
click to toggle source
# File lib/dopv/cli/command_validate.rb, line 4 def self.command_validate(base) base.class_eval do desc 'Validate a plan file.' arg_name 'plan_file' command :validate do |c| c.action do |global_options, options, args| help_now!('Validate takes excatly one argument, a plan file') if args.empty? || args.length != 1 plan_file = args[0] exit_now!("The #{plan_file} must exist and be a readable file") unless File.file?(plan_file) && File.readable?(plan_file) if Dopv.valid?(plan_file) puts('Plan is valid.') else exit_now!('Plan is NOT valid!') end end end end end