Scott Baker | 2290b05 | 2014-05-08 10:28:22 -0700 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import traceback |
| 4 | from requestrouter.models import ServiceMap |
| 5 | from observer.deleter import Deleter |
| 6 | from util.logger import Logger, logging |
| 7 | |
| 8 | parentdir = os.path.join(os.path.dirname(__file__),"..") |
| 9 | sys.path.insert(0,parentdir) |
| 10 | |
| 11 | from rrlib import RequestRouterLibrary |
| 12 | from configurationPush import ConfigurationPush |
| 13 | import rrlib_config |
| 14 | |
| 15 | logger = Logger(level=logging.INFO) |
| 16 | |
| 17 | class ServiceMapDeleter(Deleter, RequestRouterLibrary, ConfigurationPush): |
| 18 | model='ServiceMap' |
| 19 | |
| 20 | def __init__(self, **args): |
| 21 | Deleter.__init__(self, **args) |
| 22 | RequestRouterLibrary.__init__(self) |
| 23 | ConfigurationPush.__init__(self) |
| 24 | |
| 25 | |
| 26 | def call(self, pk, model_dict): |
| 27 | try: |
| 28 | servicemap = ServiceMap.objects.get(pk=pk) |
| 29 | service_uid = self.get_servicemap_uid(servicemap) |
| 30 | self.config_push(service_uid, rrlib_config.REDIR_USER, "/opt/planetstack/rr_observer/playbook/site_redir_delete.yml", "/etc/ansible/requestrouter/dnsredir/hosts") |
| 31 | self.config_push(service_uid, rrlib_config.DEMUX_USER, "/opt/planetstack/rr_observer/playbook/site_demux_delete.yml", "/etc/ansible/requestrouter/dnsdemux/hosts") |
| 32 | print "XXX delete ServiceMap %s", servicemap.name |
| 33 | return True |
| 34 | except Exception, e: |
| 35 | traceback.print_exc() |
| 36 | logger.exception("Failed to erase map '%s'" % map_name) |
| 37 | return False |
| 38 | |
| 39 | if __name__ == "__main__": |
| 40 | smap = ServiceMapDeleter() |
| 41 | smap.call( 6, {'name': 'Service23'} ) |