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



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

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



97
98
99
100
101
# File 'lib/cli/services_helper.rb', line 97

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, infra = nil) ⇒ Object



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

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

#delete_service_banner(service) ⇒ Object



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

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
44
45
46
47
48
49
50
# File 'lib/cli/services_helper.rb', line 34

def display_provisioned_services_table(services)
  return unless services && !services.empty?
  
  infra_supported = !services.detect { |a| a[:infra] }.nil?
  services_table = table do |t|
    t.headings = 'Name', 'Service'
    t.headings << 'In' if infra_supported
    services.each do |service|
      s =  [ service[:name], service[:vendor] ]
      if infra_supported
        s << ( service[:infra] ? service[:infra][:provider] : "   " )
      end
      t << s
    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

#generate_cloned_service_name(src_appname, dest_appname, src_servicename, dest_infra) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cli/services_helper.rb', line 84

def generate_cloned_service_name(src_appname,dest_appname,src_servicename,dest_infra)
  r = "%04x" % [rand(0x0100000)]
  dest_servicename = src_servicename.sub(src_appname,dest_appname).sub(/-[0-9A-Fa-f]{4,5}/,"-#{r}")
  if src_servicename == dest_servicename
    if dest_infra
      dest_servicename = "#{dest_servicename}-#{dest_infra}"
    else
      dest_servicename = "#{dest_servicename}-#{r}"
    end
  end
  dest_servicename
end

#random_service_name(service) ⇒ Object



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

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

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



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

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