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, #config, #confirmed?, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #password, #redirect, #release, #remove_option, #target, #target_name, #username, #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, #latest_release_versions, #prepare_deployment_manifest, #prompt_for_job_and_index, #resolve_release_aliases, #warn_about_stemcell_changes

Constructor Details

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

Instance Method Details

#delete(snapshot_cid) ⇒ Object



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

def delete(snapshot_cid)
  auth_required

  deployment_name = prepare_deployment_manifest['name']
  say("Deployment `#{deployment_name.make_green}'")

  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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cli/commands/snapshot.rb', line 77

def delete_all
  auth_required

  deployment_name = prepare_deployment_manifest['name']
  say("Deployment `#{deployment_name.make_green}'")

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

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

  deployment_name = prepare_deployment_manifest['name']
  say("Deployment `#{deployment_name.make_green}'")

  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



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

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

  deployment_name = prepare_deployment_manifest['name']
  say("Deployment `#{deployment_name.make_green}'")

  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