Module: VMC::Cli::ServicesHelper

Included in:
Command::Apps, Command::Services, ManifestHelper
Defined in:
lib/cli/services_helper.rb

Instance Method Summary collapse

Instance Method Details

#bind_service_banner(service, appname, check_restart = true) ⇒ Object



52
53
54
55
56
57
# File 'lib/cli/services_helper.rb', line 52

def bind_service_banner(service, appname, check_restart=true)
  display "Binding Service [#{service}]: ", false
  client.bind_service(service, appname)
  display 'OK'.green
  check_app_for_restart(appname) if check_restart
end

#check_app_for_restart(appname) ⇒ Object



77
78
79
80
81
# File 'lib/cli/services_helper.rb', line 77

def check_app_for_restart(appname)
  app = client.app_info(appname)
  cmd = VMC::Cli::Command::Apps.new(@options)
  cmd.restart(appname) if app[:state] == 'STARTED'
end

#create_service_banner(service, name, display_name = false) ⇒ Object



45
46
47
48
49
50
# File 'lib/cli/services_helper.rb', line 45

def create_service_banner(service, name, display_name=false)
  sn = " [#{name}]" if display_name
  display "Creating Service#{sn}: ", false
  client.create_service(service, name)
  display 'OK'.green
end

#delete_service_banner(service) ⇒ Object



66
67
68
69
70
# File 'lib/cli/services_helper.rb', line 66

def delete_service_banner(service)
  display "Deleting service [#{service}]: ", false
  client.delete_service(service)
  display 'OK'.green
end

#display_provisioned_services(services = nil) ⇒ Object



28
29
30
31
32
# File 'lib/cli/services_helper.rb', line 28

def display_provisioned_services(services=nil)
  services ||= client.services
  display "\n=========== Provisioned Services ============\n\n"
  display_provisioned_services_table(services)
end

#display_provisioned_services_table(services) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/cli/services_helper.rb', line 34

def display_provisioned_services_table(services)
  return unless services && !services.empty?
  services_table = table do |t|
    t.headings = 'Name', 'Service'
    services.each do |service|
      t << [ service[:name], service[:vendor] ]
    end
  end
  display services_table
end

#display_system_services(services = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cli/services_helper.rb', line 4

def display_system_services(services=nil)
  services ||= client.services_info

  display "\n============== System Services ==============\n\n"

  return display "No system services available" if services.empty?

  displayed_services = []
  services.each do |service_type, value|
    value.each do |vendor, version|
      version.each do |version_str, service|
        displayed_services << [ vendor, version_str, service[:description] ]
      end
    end
  end
  displayed_services.sort! { |a, b| a.first.to_s <=> b.first.to_s}

  services_table = table do |t|
    t.headings = 'Service', 'Version', 'Description'
    displayed_services.each { |s| t << s }
  end
  display services_table
end

#random_service_name(service) ⇒ Object



72
73
74
75
# File 'lib/cli/services_helper.rb', line 72

def random_service_name(service)
  r = "%04x" % [rand(0x0100000)]
  "#{service.to_s}-#{r}"
end

#unbind_service_banner(service, appname, check_restart = true) ⇒ Object



59
60
61
62
63
64
# File 'lib/cli/services_helper.rb', line 59

def unbind_service_banner(service, appname, check_restart=true)
  display "Unbinding Service [#{service}]: ", false
  client.unbind_service(service, appname)
  display 'OK'.green
  check_app_for_restart(appname) if check_restart
end