Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 1 | inherit obmc-phosphor-utils |
| 2 | DISCOVERY_SVC_PACKAGES ?= "${PN}" |
| 3 | |
| 4 | python() { |
| 5 | avahi_enabled = bb.utils.contains( |
| 6 | 'DISTRO_FEATURES', 'avahi', 'true', 'false', d) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 7 | slp_enabled = bb.utils.contains( |
| 8 | 'DISTRO_FEATURES', 'slp', 'true', 'false', d) |
| 9 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 10 | |
| 11 | if not avahi_enabled and slp_enabled: |
| 12 | return |
| 13 | |
| 14 | syscnfdir = d.getVar('sysconfdir', True) |
| 15 | dest_dir = d.getVar('D', True) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 16 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 17 | set_append(d, 'AVAHI_SERVICES_DIR', os.path.join( |
| 18 | dest_dir+syscnfdir, |
| 19 | 'avahi', |
| 20 | 'services')) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 21 | set_append(d, 'SLP_SERVICES_DIR', os.path.join( |
| 22 | dest_dir+syscnfdir, |
| 23 | 'slp', |
| 24 | 'services')) |
| 25 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 26 | |
| 27 | for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'): |
| 28 | for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg): |
| 29 | if avahi_enabled: |
| 30 | set_append(d, 'RRECOMMENDS_%s' % pkg, 'avahi-daemon') |
| 31 | svc_name, svc_type, svc_port = service.split(':') |
| 32 | set_append(d, 'FILES_%s' % pkg, os.path.join( |
| 33 | syscnfdir, |
| 34 | 'avahi', |
| 35 | 'services', |
| 36 | '%s.service' % svc_name)) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 37 | |
| 38 | if slp_enabled: |
| 39 | set_append(d, 'RRECOMMENDS_%s' % pkg, 'slpd-lite') |
| 40 | svc_name, svc_type, svc_port = service.split(':') |
| 41 | set_append(d, 'FILES_%s' % pkg, os.path.join( |
| 42 | syscnfdir, |
| 43 | 'slp', |
| 44 | 'services', |
| 45 | '%s.service' % svc_name)) |
| 46 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | python discovery_services_postinstall() { |
| 50 | avahi_enabled = bb.utils.contains( |
| 51 | 'DISTRO_FEATURES', 'avahi', 'true', 'false', d) |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 52 | slp_enabled = bb.utils.contains( |
| 53 | 'DISTRO_FEATURES', 'slp', 'true', 'false', d) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 54 | |
| 55 | if not avahi_enabled and slp_enabled: |
| 56 | return |
| 57 | |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 58 | avahi_service_dir = d.getVar('AVAHI_SERVICES_DIR', True) |
| 59 | slp_service_dir = d.getVar('SLP_SERVICES_DIR', True) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 60 | |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 61 | if not os.path.exists(avahi_service_dir): |
| 62 | os.makedirs(avahi_service_dir) |
| 63 | |
| 64 | if not os.path.exists(slp_service_dir): |
| 65 | os.makedirs(slp_service_dir) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 66 | |
| 67 | def register_service_avahi(d, service_name, service_type, service_port): |
| 68 | service_file = os.path.join( |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 69 | avahi_service_dir, |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 70 | '%s.service' % service_name) |
| 71 | with open(service_file, 'w') as fd: |
| 72 | fd.write('<?xml version="1.0" ?>\n') |
| 73 | fd.write('<!DOCTYPE service-group SYSTEM "avahi-service.dtd">\n') |
| 74 | fd.write('<service-group>\n') |
Ratan Gupta | 04fe31f | 2016-10-07 06:55:00 -0500 | [diff] [blame] | 75 | fd.write(' <name>%s</name>\n' % service_name) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 76 | fd.write(' <service>\n') |
Ratan Gupta | 04fe31f | 2016-10-07 06:55:00 -0500 | [diff] [blame] | 77 | fd.write(' <type>%s</type>\n' % service_type) |
| 78 | fd.write(' <port>%s</port>\n' % service_port) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 79 | fd.write(' </service>\n') |
| 80 | fd.write('</service-group>\n') |
| 81 | |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 82 | |
| 83 | def register_service_slp(d, service_name, service_type, service_port): |
| 84 | service_file = os.path.join( |
| 85 | slp_service_dir, |
| 86 | '%s.service' % service_name) |
| 87 | with open(service_file, 'w') as fd: |
| 88 | fd.write('%s %s %s' % (service_name, service_type, service_port)) |
| 89 | |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 90 | def register_services(d,pkg): |
| 91 | for service in listvar_to_list(d, 'REGISTERED_SERVICES_%s' % pkg): |
| 92 | svc_info = service.split(":") |
| 93 | try: |
| 94 | svc_name, svc_type, svc_port = svc_info |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 95 | except: |
| 96 | continue |
| 97 | if avahi_enabled: |
Ratan | 96da489 | 2016-11-17 16:06:21 +0530 | [diff] [blame] | 98 | avahi_svc_type = "_" + svc_name + "._" + svc_type |
| 99 | register_service_avahi(d, svc_name, avahi_svc_type, svc_port) |
| 100 | if slp_enabled: |
| 101 | register_service_slp(d, svc_name, svc_type, svc_port) |
Ratan Gupta | 653779c | 2016-10-01 14:57:15 -0500 | [diff] [blame] | 102 | |
| 103 | for pkg in listvar_to_list(d, 'DISCOVERY_SVC_PACKAGES'): |
| 104 | register_services(d, pkg) |
| 105 | |
| 106 | } |
| 107 | do_install[postfuncs] += "discovery_services_postinstall" |