Class: Morpheus::Cli::Workflows

Inherits:
Object
  • Object
show all
Includes:
CliCommand, Term::ANSIColor
Defined in:
lib/morpheus/cli/workflows.rb

Instance Method Summary collapse

Methods included from CliCommand

accountScopeOptions, genericOptions, included

Constructor Details

#initialize ⇒ Workflows

Returns a new instance of Workflows.



12
13
14
# File 'lib/morpheus/cli/workflows.rb', line 12

def initialize() 
	@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance	
end

Instance Method Details

#add(args) ⇒ Object



95
96
# File 'lib/morpheus/cli/workflows.rb', line 95

def add(args)
end

#connect(opts) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/morpheus/cli/workflows.rb', line 16

def connect(opts)
	if opts[:remote]
		@appliance_url = opts[:remote]
		@appliance_name = opts[:remote]
		@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
	else
		@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
	end
	@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)		
	@tasks_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).tasks
	@task_sets_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).task_sets
	if @access_token.empty?
		print red,bold, "\nInvalid Credentials. Unable to acquire access token. Please verify your credentials and try again.\n\n",reset
		exit 1
	end
end

#handle(args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/morpheus/cli/workflows.rb', line 34

def handle(args) 
	if args.empty?
		puts "\nUsage: morpheus workflows [list,add,remove]\n\n"
		return 
	end

	case args[0]
		when 'list'
			list(args[1..-1])
		when 'add'
			add(args[1..-1])
		when 'remove'
			remove(args[1..-1])
		else
			puts "\nUsage: morpheus workflows [list,add,remove]\n\n"
			exit 127
	end
end

#list(args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/morpheus/cli/workflows.rb', line 53

def list(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus workflows list [-s] [-o] [-m]"
		Morpheus::Cli::CliCommand.genericOptions(opts,options)
	end
	optparse.parse(args)
	connect(options)
	begin
		params = {}
		if options[:offset]
			params[:offset] = options[:offset]
		end
		if options[:max]
			params[:max] = options[:max]
		end
		if options[:phrase]
			params[:phrase] = options[:phrase]
		end
		json_response = @task_sets_interface.get(params)
		if options[:json]
				print JSON.pretty_generate(json_response)
		else
			task_sets = json_response['taskSets']
			print "\n" ,cyan, bold, "Morpheus Workflows\n","==================", reset, "\n\n"
			if task_sets.empty?
				puts yellow,"No workflows currently configured.",reset
			else
				print cyan
				tasks_table_data = task_sets.collect do |task_set|
					{name: task_set['name'], id: task_set['id']}
				end
				tp tasks_table_data, :id, :name
			end
			print reset,"\n\n"
		end
	rescue RestClient::Exception => e
		::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
		exit 1
	end
end

#remove(args) ⇒ Object



98
99
# File 'lib/morpheus/cli/workflows.rb', line 98

def remove(args)
end