Class: Bosh::Cli::Command::Snapshot

Inherits:
Base show all
Defined in:
lib/cli/commands/snapshot.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

#args, #exit_code, #info, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #cache_dir, #config, #confirmed?, #credentials, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #progress_renderer, #redirect, #release, #remove_option, #run_nested_command, #show_current_state, #target, #target_name, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

#desc, #method_added, #option, #register_command, #usage

Methods included from DeploymentHelper

#build_manifest, #cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_unique_in_deployment?, #jobs_and_indexes, #prepare_deployment_manifest, #prompt_for_errand_name, #prompt_for_job_and_index

Constructor Details

This class inherits a constructor from Bosh::Cli::Command::Base

Instance Method Details

#delete(snapshot_cid) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cli/commands/snapshot.rb', line 66

def delete(snapshot_cid)
  auth_required

  deployment_name = prepare_deployment_manifest(show_state: true).name

  unless confirmed?("Are you sure you want to delete snapshot '#{snapshot_cid}'?")
    say('Canceled deleting snapshot'.make_green)
    return
  end

  status, task_id = director.delete_snapshot(deployment_name, snapshot_cid)

  task_report(status, task_id, "Deleted Snapshot '#{snapshot_cid}'")
end

#delete_allObject


83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cli/commands/snapshot.rb', line 83

def delete_all
  auth_required

  deployment_name = prepare_deployment_manifest(show_state: true).name

  unless confirmed?("Are you sure you want to delete all snapshots of deployment '#{deployment_name}'?")
    say('Canceled deleting snapshots'.make_green)
    return
  end

  status, task_id = director.delete_all_snapshots(deployment_name)

  task_report(status, task_id, "Deleted all snapshots of deployment '#{deployment_name}'")
end

#list(job = nil, index = nil) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cli/commands/snapshot.rb', line 5

def list(job = nil, index = nil)
  auth_required

  deployment_name = prepare_deployment_manifest(show_state: true).name

  snapshots = director.list_snapshots(deployment_name, job, index)

  if snapshots.empty?
    nl
    say('No snapshots')
    nl
    return
  end

  sorted = snapshots.sort do |a, b|
    s = a['job'].to_s <=> b['job'].to_s
    if a['uuid']
      s = a['uuid'].to_i <=> b['uuid'].to_i if s == 0
    else
      s = a['index'].to_i <=> b['index'].to_i if s == 0
    end
    s = a['created_at'].to_s <=> b['created_at'].to_s if s == 0
    s
  end

  snapshots_table = table do |t|
    t.headings = ['Job/ID', 'Snapshot CID', 'Created at', 'Clean']

    sorted.each do |snapshot|
      job = "#{snapshot['job'] || 'unknown'}/#{snapshot['uuid'] || 'unknown'} (#{snapshot['index'] || 'unknown'})"
      t << [job, snapshot['snapshot_cid'], snapshot['created_at'], snapshot['clean']]
    end
  end

  nl
  say(snapshots_table)
  nl
  say('Snapshots total: %d' % snapshots.size)
end

#take(job = nil, index = nil) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cli/commands/snapshot.rb', line 47

def take(job = nil, index = nil)
  auth_required

  deployment_name = prepare_deployment_manifest(show_state: true).name

  unless job && index
    unless confirmed?("Are you sure you want to take a snapshot of all deployment '#{deployment_name}'?")
      say('Canceled taking snapshot'.make_green)
      return
    end
  end

  status, task_id = director.take_snapshot(deployment_name, job, index)

  task_report(status, task_id, 'Snapshot taken')
end