Class: Bosh::Cli::Client::Director

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/client/director.rb

Constant Summary collapse

DIRECTOR_HTTP_ERROR_CODES =
[400, 401, 403, 404, 500]
API_TIMEOUT =
86400 * 3
CONNECT_TIMEOUT =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(director_uri, credentials = nil, options = {}) ⇒ Director

Options can include:

  • :no_track => true - do not use TaskTracker for long-running

    +request_and_track+ calls
    


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cli/client/director.rb', line 25

def initialize(director_uri, credentials = nil, options = {})
  if director_uri.nil? || director_uri =~ /^\s*$/
    raise DirectorMissing, 'no director URI given'
  end

  @director_uri        = URI.parse(director_uri)
  @director_ip         = Resolv.getaddresses(@director_uri.host).last
  @scheme              = @director_uri.scheme
  @port                = @director_uri.port
  @credentials         = credentials
  @track_tasks         = !options.delete(:no_track)
  @num_retries         = options.fetch(:num_retries, 5)
  @retry_wait_interval = options.fetch(:retry_wait_interval, 5)
  @ca_cert             = options[:ca_cert]
end

Instance Attribute Details

#director_uriObject (readonly)

Returns the value of attribute director_uri.



20
21
22
# File 'lib/cli/client/director.rb', line 20

def director_uri
  @director_uri
end

Instance Method Details

#apply_resolutions(deployment_name, resolutions, options = {}) ⇒ Object



482
483
484
485
486
487
488
489
490
# File 'lib/cli/client/director.rb', line 482

def apply_resolutions(deployment_name, resolutions, options = {})
  options = options.dup

  url                    = "/deployments/#{deployment_name}/problems"
  options[:content_type] = 'application/json'
  options[:payload]      = JSON.generate('resolutions' => resolutions)

  request_and_track(:put, url, options)
end

#attach_disk(deployment_name, job_name, instance_id, disk_cid) ⇒ Object



183
184
185
# File 'lib/cli/client/director.rb', line 183

def attach_disk(deployment_name, job_name, instance_id, disk_cid)
  request_and_track(:put, "/disks/#{disk_cid}/attachments?deployment=#{deployment_name}&job=#{job_name}&instance_id=#{instance_id}")
end

#authenticated?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cli/client/director.rb', line 66

def authenticated?
  # getting status verifies credentials
  # if credentials are wrong it will raise DirectorError
  status = get_status
  # Backward compatibility: older directors return 200
  # only for logged in users
  return true if !status.has_key?('version')
  !status['user'].nil?
rescue DirectorError
  false
end

#cancel_task(task_id) ⇒ Object

Raises:



556
557
558
559
560
561
# File 'lib/cli/client/director.rb', line 556

def cancel_task(task_id)
  response_code, body = delete("/task/#{task_id}")
  raise AuthError if response_code == 401
  raise MissingTask, "No task##{task_id} found" if response_code == 404
  [body, response_code]
end

#change_job_state(deployment_name, manifest_yaml, job, index_or_id, new_state, options = {}) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/cli/client/director.rb', line 328

def change_job_state(deployment_name, manifest_yaml,
  job, index_or_id, new_state, options = {})
  options = options.dup

  skip_drain = !!options.delete(:skip_drain)

  url = "/deployments/#{deployment_name}/jobs/#{job}"
  url += "/#{index_or_id}" if index_or_id
  url += "?state=#{new_state}"
  url += "&skip_drain=true" if skip_drain

  options[:payload]      = manifest_yaml
  options[:content_type] = 'text/yaml'

  request_and_track(:put, url, options)
end

#change_vm_resurrection(deployment_name, job_name, index, value) ⇒ Object



345
346
347
348
349
# File 'lib/cli/client/director.rb', line 345

def change_vm_resurrection(deployment_name, job_name, index, value)
  url     = "/deployments/#{deployment_name}/jobs/#{job_name}/#{index}/resurrection"
  payload = JSON.generate('resurrection_paused' => value)
  put(url, 'application/json', payload)
end

#change_vm_resurrection_for_all(value) ⇒ Object



351
352
353
354
355
# File 'lib/cli/client/director.rb', line 351

def change_vm_resurrection_for_all(value)
  url     = "/resurrection"
  payload = JSON.generate('resurrection_paused' => value)
  put(url, 'application/json', payload)
end

#check_director_restart(poll_interval, timeout) ⇒ Object



576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/cli/client/director.rb', line 576

def check_director_restart(poll_interval, timeout)
  current_time = start_time = Time.now()

  #step 1, wait until director is stopped
  while current_time.to_i - start_time.to_i <= timeout do
    status, body = get_json_with_status('/info')
    break if status != 200

    sleep(poll_interval)
    current_time = Time.now()
  end

  #step 2, wait until director is started
  while current_time.to_i - start_time.to_i <= timeout do
    status, body = get_json_with_status('/info')
    return true if status == 200

    sleep(poll_interval)
    current_time = Time.now()
  end

  return false
end

#cleanup(config = {}) ⇒ Object



672
673
674
675
676
677
# File 'lib/cli/client/director.rb', line 672

def cleanup(config = {})
  options = {}
  options[:payload] = JSON.generate('config' => config)
  options[:content_type] = 'application/json'
  request_and_track(:post, '/cleanup', options)
end

#cleanup_ssh(deployment_name, job, user_regex, id, options = {}) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/cli/client/director.rb', line 305

def cleanup_ssh(deployment_name, job, user_regex, id, options = {})
  options = options.dup

  url = "/deployments/#{deployment_name}/ssh"

  payload = {
    'command'         => 'cleanup',
    'deployment_name' => deployment_name,
    'target'          => {
      'job'     => job,
      'indexes' => (id || []).compact,
      'ids' => (id || []).compact,
    },
    'params'          => { 'user_regex' => user_regex }
  }

  options[:payload]      = JSON.generate(payload)
  options[:content_type] = 'application/json'
  options[:task_success_state] = :queued

  request_and_track(:post, url, options)
end

#create_backupObject



563
564
565
# File 'lib/cli/client/director.rb', line 563

def create_backup
  request_and_track(:post, '/backups', {})
end

#create_property(deployment_name, property_name, value) ⇒ Object



406
407
408
409
410
# File 'lib/cli/client/director.rb', line 406

def create_property(deployment_name, property_name, value)
  url     = "/deployments/#{deployment_name}/properties"
  payload = JSON.generate('name' => property_name, 'value' => value)
  post(url, 'application/json', payload)
end

#create_user(username, password) ⇒ Object



78
79
80
81
82
# File 'lib/cli/client/director.rb', line 78

def create_user(username, password)
  payload          = JSON.generate('username' => username, 'password' => password)
  response_code, _ = post('/users', 'application/json', payload)
  response_code == 204
end

#delete(uri, content_type = nil, payload = nil, headers = {}, options = {}) ⇒ Object



691
692
693
# File 'lib/cli/client/director.rb', line 691

def delete(uri, content_type = nil, payload = nil, headers = {}, options = {})
  request(:delete, uri, content_type, payload, headers, options)
end

#delete_all_snapshots(deployment_name, options = {}) ⇒ Object



454
455
456
457
458
459
460
# File 'lib/cli/client/director.rb', line 454

def delete_all_snapshots(deployment_name, options = {})
  options = options.dup

  url = "/deployments/#{deployment_name}/snapshots"

  request_and_track(:delete, url, options)
end

#delete_deployment(name, options = {}) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/cli/client/director.rb', line 224

def delete_deployment(name, options = {})
  options = options.dup
  force   = options.delete(:force)

  url = "/deployments/#{name}"

  extras = []
  extras << ['force', 'true'] if force

  request_and_track(:delete, add_query_string(url, extras), options)
end

#delete_orphan_disk_by_disk_cid(orphan_disk_cid) ⇒ Object



187
188
189
# File 'lib/cli/client/director.rb', line 187

def delete_orphan_disk_by_disk_cid(orphan_disk_cid)
  request_and_track(:delete, "/disks/#{orphan_disk_cid}")
end

#delete_property(deployment_name, property_name) ⇒ Object



418
419
420
421
# File 'lib/cli/client/director.rb', line 418

def delete_property(deployment_name, property_name)
  url = "/deployments/#{deployment_name}/properties/#{property_name}"
  delete(url, 'application/json')
end

#delete_release(name, options = {}) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/cli/client/director.rb', line 236

def delete_release(name, options = {})
  options = options.dup
  force   = options.delete(:force)
  version = options.delete(:version)

  url = "/releases/#{name}"

  extras = []
  extras << ['force', 'true'] if force
  extras << ['version', version] if version

  request_and_track(:delete, add_query_string(url, extras), options)
end

#delete_snapshot(deployment_name, snapshot_cid, options = {}) ⇒ Object



462
463
464
465
466
467
468
# File 'lib/cli/client/director.rb', line 462

def delete_snapshot(deployment_name, snapshot_cid, options = {})
  options = options.dup

  url = "/deployments/#{deployment_name}/snapshots/#{snapshot_cid}"

  request_and_track(:delete, url, options)
end

#delete_stemcell(name, version, options = {}) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/cli/client/director.rb', line 212

def delete_stemcell(name, version, options = {})
  options = options.dup
  force   = options.delete(:force)

  url = "/stemcells/#{name}/#{version}"

  extras = []
  extras << ['force', 'true'] if force

  request_and_track(:delete, add_query_string(url, extras), options)
end

#delete_user(username) ⇒ Object



84
85
86
87
# File 'lib/cli/client/director.rb', line 84

def delete_user(username)
  response_code, _ = delete("/users/#{username}")
  response_code == 204
end

#deploy(manifest_yaml, options = {}) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/cli/client/director.rb', line 250

def deploy(manifest_yaml, options = {})
  options = options.dup

  recreate               = options.delete(:recreate)
  skip_drain             = options.delete(:skip_drain)
  context                = options.delete(:context)
  options[:content_type] = 'text/yaml'
  options[:payload]      = manifest_yaml

  url = '/deployments'

  extras = []
  extras << ['recreate', 'true'] if recreate
  extras << ['context', JSON.dump(context)] if context
  extras << ['skip_drain', skip_drain] if skip_drain

  request_and_track(:post, add_query_string(url, extras), options)
end

#diff_deployment(name, manifest_yaml) ⇒ Object



269
270
271
272
273
274
275
276
# File 'lib/cli/client/director.rb', line 269

def diff_deployment(name, manifest_yaml)
  status, body = post("/deployments/#{name}/diff", 'text/yaml', manifest_yaml)
  if status == 200
    JSON.parse(body)
  else
    err(parse_error_message(status, body))
  end
end

#download_resource(id) ⇒ Object



394
395
396
397
398
399
400
401
402
403
404
# File 'lib/cli/client/director.rb', line 394

def download_resource(id)
  status, tmp_file, _ = get("/resources/#{id}",
                            nil, nil, {}, :file => true)

  if status == 200
    tmp_file
  else
    raise DirectorError,
          "Cannot download resource `#{id}': HTTP status #{status}"
  end
end

#exists?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'lib/cli/client/director.rb', line 45

def exists?
  get_status
  true
rescue AuthError
  true # For compatibility with directors that return 401 for /info
rescue DirectorError
  false
end

#fetch_backupObject



567
568
569
570
# File 'lib/cli/client/director.rb', line 567

def fetch_backup
  _, path, _ = get('/backups', nil, nil, {}, :file => true)
  path
end

#fetch_logs(deployment_name, job_name, index, log_type, filters = nil, options = {}) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/cli/client/director.rb', line 357

def fetch_logs(deployment_name, job_name, index, log_type,
  filters = nil, options = {})
  options = options.dup

  url = "/deployments/#{deployment_name}/jobs/#{job_name}"
  url += "/#{index}/logs?type=#{log_type}&filters=#{filters}"

  status, task_id = request_and_track(:get, url, options)

  return nil if status != :done
  get_task_result(task_id)
end

#fetch_vm_state(deployment_name, options = {}, full = true) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/cli/client/director.rb', line 370

def fetch_vm_state(deployment_name, options = {}, full = true)
  options = options.dup

  url = "/deployments/#{deployment_name}/vms"

  if full
    status, task_id = request_and_track(:get, "#{url}?format=full", options)

    raise DirectorError, 'Failed to fetch VMs information from director' if status != :done

    output = get_task_result_log(task_id)
  else
    status, output, _ = get(url, nil, nil, {}, options)

    raise DirectorError, 'Failed to fetch VMs information from director' if status != 200
  end

  output = output.to_s.split("\n").map do |vm_state|
    JSON.parse(vm_state)
  end

  output.flatten
end

#get(uri, content_type = nil, payload = nil, headers = {}, options = {}) ⇒ Object



687
688
689
# File 'lib/cli/client/director.rb', line 687

def get(uri, content_type = nil, payload = nil, headers = {}, options = {})
  request(:get, uri, content_type, payload, headers, options)
end

#get_cloud_configObject



656
657
658
659
660
661
662
663
664
665
# File 'lib/cli/client/director.rb', line 656

def get_cloud_config
  _, cloud_configs = get_json_with_status('/cloud_configs?limit=1')
  latest = cloud_configs.first

  if !latest.nil?
    Bosh::Cli::CloudConfig.new(
      properties: latest["properties"],
      created_at: latest["created_at"])
  end
end

#get_current_timeObject



492
493
494
495
# File 'lib/cli/client/director.rb', line 492

def get_current_time
  _, _, headers = get('/info')
  Time.parse(headers[:date]) rescue nil
end

#get_deployment(name) ⇒ Object



173
174
175
176
# File 'lib/cli/client/director.rb', line 173

def get_deployment(name)
  _, body = get_json_with_status("/deployments/#{name}")
  body
end

#get_property(deployment_name, property_name) ⇒ Object



423
424
425
426
# File 'lib/cli/client/director.rb', line 423

def get_property(deployment_name, property_name)
  url = "/deployments/#{deployment_name}/properties/#{property_name}"
  get_json_with_status(url)
end

#get_release(name) ⇒ Object



138
139
140
# File 'lib/cli/client/director.rb', line 138

def get_release(name)
  get_json("/releases/#{name}")
end

#get_statusObject



110
111
112
# File 'lib/cli/client/director.rb', line 110

def get_status
  get_json('/info')
end

#get_task(task_id) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/cli/client/director.rb', line 503

def get_task(task_id)
  response_code, body = get("/tasks/#{task_id}")
  raise AuthError if response_code == 401
  raise MissingTask, "Task #{task_id} not found" if response_code == 404

  if response_code != 200
    raise TaskTrackError, "Got HTTP #{response_code} " +
      'while tracking task state'
  end

  JSON.parse(body)
rescue JSON::ParserError
  raise TaskTrackError, 'Cannot parse task JSON, ' +
    'incompatible director version'
end

#get_task_output(task_id, offset, log_type = nil) ⇒ Object



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/cli/client/director.rb', line 532

def get_task_output(task_id, offset, log_type = nil)
  uri = "/tasks/#{task_id}/output"
  uri += "?type=#{log_type}" if log_type

  headers                      = { 'Range' => "bytes=#{offset}-" }
  response_code, body, headers = get(uri, nil, nil, headers)

  if response_code == 206 &&
    headers[:content_range].to_s =~ /bytes \d+-(\d+)\/\d+/
    new_offset = $1.to_i + 1
  else
    new_offset = nil
    # Delete the "Byte range unsatisfiable" message
    body = nil if response_code == 416
  end

  # backward compatible with renaming soap log to cpi log
  if response_code == 204 && log_type == 'cpi'
    get_task_output(task_id, offset, 'soap')
  else
    [body, new_offset]
  end
end

#get_task_result(task_id) ⇒ Object



523
524
525
# File 'lib/cli/client/director.rb', line 523

def get_task_result(task_id)
  get_task(task_id)['result']
end

#get_task_result_log(task_id) ⇒ Object



527
528
529
530
# File 'lib/cli/client/director.rb', line 527

def get_task_result_log(task_id)
  log, _ = get_task_output(task_id, 0, 'result')
  log
end

#get_task_state(task_id) ⇒ Object



519
520
521
# File 'lib/cli/client/director.rb', line 519

def get_task_state(task_id)
  get_task(task_id)['state']
end

#get_time_differenceObject



497
498
499
500
501
# File 'lib/cli/client/director.rb', line 497

def get_time_difference
  # This includes the round-trip to director
  ctime = get_current_time
  ctime ? Time.now - ctime : 0
end

#get_versionObject



106
107
108
# File 'lib/cli/client/director.rb', line 106

def get_version
  get_status['version']
end

#inspect_release(name, version) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/cli/client/director.rb', line 142

def inspect_release(name, version)
  url = "/releases/#{name}"

  extras = []
  extras << ['version', version]

  get_json(add_query_string(url, extras))
end

#list_deploymentsObject



122
123
124
# File 'lib/cli/client/director.rb', line 122

def list_deployments
  get_json('/deployments')
end

#list_errands(deployment_name) ⇒ Object



126
127
128
# File 'lib/cli/client/director.rb', line 126

def list_errands(deployment_name)
  get_json("/deployments/#{deployment_name}/errands")
end

#list_locksObject



600
601
602
# File 'lib/cli/client/director.rb', line 600

def list_locks
  get_json('/locks')
end

#list_orphan_disksObject



191
192
193
194
# File 'lib/cli/client/director.rb', line 191

def list_orphan_disks
  _, body = get_json_with_status('/disks')
  body
end

#list_problems(deployment_name) ⇒ Object



477
478
479
480
# File 'lib/cli/client/director.rb', line 477

def list_problems(deployment_name)
  url = "/deployments/#{deployment_name}/problems"
  get_json(url)
end

#list_properties(deployment_name) ⇒ Object



428
429
430
431
# File 'lib/cli/client/director.rb', line 428

def list_properties(deployment_name)
  url = "/deployments/#{deployment_name}/properties"
  get_json(url)
end

#list_recent_tasks(count = 30, verbose = 1) ⇒ Object



134
135
136
# File 'lib/cli/client/director.rb', line 134

def list_recent_tasks(count = 30, verbose = 1)
  get_json("/tasks?limit=#{count}&verbose=#{verbose}")
end

#list_releasesObject



118
119
120
# File 'lib/cli/client/director.rb', line 118

def list_releases
  get_json('/releases')
end

#list_running_tasks(verbose = 1) ⇒ Object



130
131
132
# File 'lib/cli/client/director.rb', line 130

def list_running_tasks(verbose = 1)
  get_json("/tasks?state=processing,cancelling,queued&verbose=#{verbose}")
end

#list_snapshots(deployment_name, job = nil, index = nil) ⇒ Object



445
446
447
448
449
450
451
452
# File 'lib/cli/client/director.rb', line 445

def list_snapshots(deployment_name, job = nil, index = nil)
  if job && index
    url = "/deployments/#{deployment_name}/jobs/#{job}/#{index}/snapshots"
  else
    url = "/deployments/#{deployment_name}/snapshots"
  end
  get_json(url)
end

#list_stemcellsObject



114
115
116
# File 'lib/cli/client/director.rb', line 114

def list_stemcells
  get_json('/stemcells')
end

#list_vms(name) ⇒ Object



178
179
180
181
# File 'lib/cli/client/director.rb', line 178

def list_vms(name)
  _, body = get_json_with_status("/deployments/#{name}/vms")
  body
end

#login(username, password) ⇒ Object



61
62
63
64
# File 'lib/cli/client/director.rb', line 61

def (username, password)
  @credentials = BasicCredentials.new(username, password)
  authenticated?
end

#match_compiled_packages(manifest_yaml) ⇒ Object



162
163
164
165
166
167
168
169
170
171
# File 'lib/cli/client/director.rb', line 162

def match_compiled_packages(manifest_yaml)
  url          = '/packages/matches_compiled'
  status, body = post(url, 'text/yaml', manifest_yaml)

  if status == 200
    JSON.parse(body)
  else
    err(parse_error_message(status, body))
  end
end

#match_packages(manifest_yaml) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/cli/client/director.rb', line 151

def match_packages(manifest_yaml)
  url          = '/packages/matches'
  status, body = post(url, 'text/yaml', manifest_yaml)

  if status == 200
    JSON.parse(body)
  else
    err(parse_error_message(status, body))
  end
end

#perform_cloud_scan(deployment_name, options = {}) ⇒ Object



470
471
472
473
474
475
# File 'lib/cli/client/director.rb', line 470

def perform_cloud_scan(deployment_name, options = {})
  options = options.dup
  url     = "/deployments/#{deployment_name}/scans"

  request_and_track(:post, url, options)
end

#post(uri, content_type = nil, payload = nil, headers = {}, options = {}) ⇒ Object



679
680
681
# File 'lib/cli/client/director.rb', line 679

def post(uri, content_type = nil, payload = nil, headers = {}, options = {})
  request(:post, uri, content_type, payload, headers, options)
end

#put(uri, content_type = nil, payload = nil, headers = {}, options = {}) ⇒ Object



683
684
685
# File 'lib/cli/client/director.rb', line 683

def put(uri, content_type = nil, payload = nil, headers = {}, options = {})
  request(:put, uri, content_type, payload, headers, options)
end

#request_and_track(method, uri, options = {}) ⇒ Object

Perform director HTTP request and track director task (if request started one).

Parameters:

  • method (Symbol)

    HTTP method

  • uri (String)

    URI

  • options (Hash) (defaults to: {})

    Request and tracking options



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/cli/client/director.rb', line 610

def request_and_track(method, uri, options = {})
  options = options.dup

  content_type = options.delete(:content_type)
  payload      = options.delete(:payload)
  track_opts   = options

  http_status, _, headers = request(method, uri, content_type, payload)
  location                = headers[:location]
  redirected              = [302, 303].include? http_status
  task_id                 = nil

  if redirected
    if location =~ /\/tasks\/(\d+)\/?$/ # Looks like we received task URI
      task_id = $1
      if @track_tasks
        tracker = Bosh::Cli::TaskTracking::TaskTracker.new(self, task_id, track_opts)
        status  = tracker.track
      else
        status = :running
      end
    else
      status = :non_trackable
    end
  else
    status = :failed
  end

  [status, task_id]
end

#restore_db(filename) ⇒ Object



572
573
574
# File 'lib/cli/client/director.rb', line 572

def restore_db(filename)
  upload_without_track('/restore', filename, { content_type: 'application/x-compressed' })
end

#setup_ssh(deployment_name, job, id, user, public_key, password, options = {}) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/cli/client/director.rb', line 278

def setup_ssh(deployment_name, job, id, user,
  public_key, password, options = {})
  options = options.dup

  url = "/deployments/#{deployment_name}/ssh"

  payload = {
    'command'         => 'setup',
    'deployment_name' => deployment_name,
    'target'          => {
      'job'     => job,
      'indexes' => [id].compact, # for backwards compatibility with old director
      'ids' => [id].compact,
    },
    'params'          => {
      'user'       => user,
      'public_key' => public_key,
      'password'   => password
    }
  }

  options[:payload]      = JSON.generate(payload)
  options[:content_type] = 'application/json'

  request_and_track(:post, url, options)
end

#take_snapshot(deployment_name, job = nil, index = nil, options = {}) ⇒ Object



433
434
435
436
437
438
439
440
441
442
443
# File 'lib/cli/client/director.rb', line 433

def take_snapshot(deployment_name, job = nil, index = nil, options = {})
  options = options.dup

  if job && index
    url = "/deployments/#{deployment_name}/jobs/#{job}/#{index}/snapshots"
  else
    url = "/deployments/#{deployment_name}/snapshots"
  end

  request_and_track(:post, url, options)
end

#update_cloud_config(cloud_config_yaml) ⇒ Object



667
668
669
670
# File 'lib/cli/client/director.rb', line 667

def update_cloud_config(cloud_config_yaml)
  status, _ = post('/cloud_configs', 'text/yaml', cloud_config_yaml)
  status == 201
end

#update_property(deployment_name, property_name, value) ⇒ Object



412
413
414
415
416
# File 'lib/cli/client/director.rb', line 412

def update_property(deployment_name, property_name, value)
  url     = "/deployments/#{deployment_name}/properties/#{property_name}"
  payload = JSON.generate('value' => value)
  put(url, 'application/json', payload)
end

#upload_and_track(method, uri, filename, options = {}) ⇒ Object



641
642
643
644
645
646
# File 'lib/cli/client/director.rb', line 641

def upload_and_track(method, uri, filename, options = {})
  file = FileWithProgressBar.open(filename, 'r')
  request_and_track(method, uri, options.merge(:payload => file))
ensure
  file.stop_progress_bar if file
end

#upload_release(filename, options = {}) ⇒ Object



196
197
198
199
200
201
# File 'lib/cli/client/director.rb', line 196

def upload_release(filename, options = {})
  options                = options.dup
  options[:content_type] = 'application/x-compressed'

  upload_and_track(:post, releases_path(options), filename, options)
end

#upload_remote_release(release_location, options = {}) ⇒ Object



203
204
205
206
207
208
209
210
# File 'lib/cli/client/director.rb', line 203

def upload_remote_release(release_location, options = {})
  options                = options.dup
  payload                = { 'location' => release_location }
  options[:payload]      = JSON.generate(payload)
  options[:content_type] = 'application/json'

  request_and_track(:post, releases_path(options), options)
end

#upload_remote_stemcell(stemcell_location, options = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/cli/client/director.rb', line 96

def upload_remote_stemcell(stemcell_location, options = {})
  options                = options.dup
  payload                = { 'location' => stemcell_location }
  payload[:sha1]         = options[:sha1] if options[:sha1]
  options[:payload]      = JSON.generate(payload)
  options[:content_type] = 'application/json'

  request_and_track(:post, stemcells_path(options), options)
end

#upload_stemcell(filename, options = {}) ⇒ Object



89
90
91
92
93
94
# File 'lib/cli/client/director.rb', line 89

def upload_stemcell(filename, options = {})
  options                = options.dup
  options[:content_type] = 'application/x-compressed'

  upload_and_track(:post, stemcells_path(options), filename, options)
end

#upload_without_track(uri, filename, options = {}) ⇒ Object



648
649
650
651
652
653
654
# File 'lib/cli/client/director.rb', line 648

def upload_without_track(uri, filename, options = {})
  file = FileWithProgressBar.open(filename, 'r')
  status, _ = post(uri, options[:content_type], file, {}, options)
  status
ensure
  file.stop_progress_bar if file
end

#uuidObject



41
42
43
# File 'lib/cli/client/director.rb', line 41

def uuid
  @uuid ||= get_status['uuid']
end

#wait_until_readyObject



54
55
56
57
58
59
# File 'lib/cli/client/director.rb', line 54

def wait_until_ready
  num_retries.times do
    return if exists?
    sleep retry_wait_interval
  end
end