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