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, #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, #show_current_state, #target, #target_name, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

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

Methods included from DeploymentHelper

#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cli/commands/snapshot.rb', line 57

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cli/commands/snapshot.rb', line 74

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



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
# File 'lib/cli/commands/snapshot.rb', line 7

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)

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

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

    sorted.each do |snapshot|
      job = "#{snapshot['job'] || '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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cli/commands/snapshot.rb', line 38

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