Class: Source

Inherits:
Thor
  • Object
show all
Defined in:
lib/dscli/source.rb

Instance Method Summary collapse

Instance Method Details

#delete(id) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dscli/source.rb', line 56

def delete(id)
  api = Dscli::API.new
  response = api.source_delete(id)

  if response[:http][:status] == 204
    puts "Source '#{id}' deleted successfully"
  else
    response
  end
rescue ApiResourceNotFoundError
  puts "Source '#{id}' not found. It may have been deleted."
end

#get(id) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/dscli/source.rb', line 17

def get(id)
  api = Dscli::API.new
  response = api.source_get(id)
  puts response[:data].to_yaml
rescue ApiResourceNotFoundError
  puts "Specified managed source '#{id}' was not found. It may have been deleted."
end

#list(page = 1) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/dscli/source.rb', line 4

def list(page = 1)
  api = Dscli::API.new
  results = api.source_list(page)

  puts "\nTotal Managed Sources: #{results.count}\n\n"
  puts 'ID                               | Name                 | Type                 | Status'
  puts '-----------------------------------------------------------------------------------------------------'

  results[:sources].each { |s| puts "#{s[:id]} | #{ '%-20.20s' % s[:name] } | #{ '%-20.20s' % s[:source_type] } | #{s[:status]}" }
  puts "\n"
end

#logs(id = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dscli/source.rb', line 70

def logs(id = nil)
  api = Dscli::API.new
 	results = api.source_log(id)

 puts "\nMessage count: #{results[:count]}\n\n"
 puts ' Time                     | Message                                          '
 puts '-----------------------------------------------------------------------------------------------------------------'

 results[:log_entries].each { |s| puts "#{Time.at(s[:event_time]) } | #{ '%-50.50s' % s[:message] }" }
 puts "\n"

rescue ApiResourceNotFoundError
  puts "Specified source '#{id}' not found. It may have been deleted."
end

#start(id) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dscli/source.rb', line 26

def start(id)
	api = Dscli::API.new
  response = api.source_start(id)

  if response[:http][:status] == 200
    puts "Managed source '#{id}' started successfully"
  else
    # TODO: How do we handle a different code?
    response
  end
rescue ApiResourceNotFoundError
  puts "Specified source '#{id}' not found. It may have been deleted."
end

#stop(id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dscli/source.rb', line 41

def stop(id)
	api = Dscli::API.new
  response = api.source_stop(id)

  if response[:http][:status] == 200
    puts "Managed source '#{id}' stopped successfully"
  else
    # TODO: How do we handle a different code?
    response
  end
rescue ApiResourceNotFoundError
  puts "Specified source '#{id}' not found. It may have been deleted."
end