Class: Morpheus::Cli::Snapshots
- Inherits:
-
Object
- Object
- Morpheus::Cli::Snapshots
show all
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/commands/snapshots.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Instance Method Details
#_get(arg, options) ⇒ Object
45
46
47
48
49
50
51
52
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
94
95
|
# File 'lib/morpheus/cli/commands/snapshots.rb', line 45
def _get(arg, options)
begin
@snapshots_interface.setopts(options)
if options[:dry_run]
print_dry_run @snapshots_interface.dry.get(arg.to_i)
return
end
json_response = @snapshots_interface.get(arg.to_i)
if options[:json]
puts as_json(json_response, options, "snapshot")
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "snapshot")
return 0
end
if options[:csv]
puts records_as_csv([json_response['snapshot']], options)
return 0
end
snapshot = json_response['snapshot']
print_h1 "Snapshot Details"
print cyan
description_cols = {
"ID" => 'id',
"Name" => 'name',
"Description" => 'description',
"External Id" => 'externalId',
"Status" => 'status',
"State" => 'state',
"Snapshot Type" => 'snapshotType',
"Snapshot Created" => 'snapshotCreated',
"Cloud" => 'zone.name',
"Datastore" => 'datastore',
"Parent Snapshot" => 'parentSnapshot',
"Active" => 'currentlyActive',
"Date Created" => 'dateCreated'
}
print_description_list(description_cols, snapshot)
print reset, "\n"
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return 1
end
end
|
#connect(opts) ⇒ Object
13
14
15
16
|
# File 'lib/morpheus/cli/commands/snapshots.rb', line 13
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@snapshots_interface = @api_client.snapshots
end
|
#get(args) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/morpheus/cli/commands/snapshots.rb', line 22
def get(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id]")
opts. = "Get Snapshot details." + "\n" +
"[id] is required. This is the id of the snapshot."
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
end
optparse.parse!(args)
if args.count < 1
puts_error "[id] argument is required"
puts_error optparse
return 1
end
connect(options)
id_list = parse_id_list(args)
return run_command_for_each_arg(id_list) do |arg|
_get(arg, options)
end
end
|
#handle(args) ⇒ Object
18
19
20
|
# File 'lib/morpheus/cli/commands/snapshots.rb', line 18
def handle(args)
handle_subcommand(args)
end
|
#remove(args) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/morpheus/cli/commands/snapshots.rb', line 97
def remove(args)
options = {}
snapshot_id = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id]")
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
opts. = "Remove/Delete a snapshot." + "\n" +
"[id] is required. This is the id of the snapshot to delete."
end
optparse.parse!(args)
if args.count != 1
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
end
snapshot_id = args[0].to_i
connect(options)
begin
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove a snapshot?", options)
exit 1
end
payload = {}
if options[:dry_run]
print_dry_run @snapshots_interface.dry.remove(snapshot_id, payload)
return
end
json_response = @snapshots_interface.remove(snapshot_id, payload)
if options[:json]
puts as_json(json_response, options)
else
print_green_success "Snapshot delete initiated."
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|