def consul_sync_health(*args, **kwargs): datacenter_domain = kwargs['datacenter']['qurom']['domain'] datacenter_port = kwargs['datacenter']['qurom']['port'] datacenter_cakey = kwargs['datacenter']['qurom']['cakey'] datacenter_cacert = kwargs['datacenter']['qurom']['cacert'] group_name = kwargs['group_name'] healths = kwargs['healths'] logger.debug('xxxxxxxxxxxxxxxxxxx') consul_handler = commConsul.CommConsul(datacenter_cacert, datacenter_cakey, LOG=logger) consul_handler.connect(datacenter_domain, datacenter_port) consul_key = 'deploy/deployGroup/%s/checks' % group_name consul_value = json.dumps(healths) logger.debug('healths is {0}'.format(consul_value)) if healths: consul_handler.put_values(consul_key, consul_value) else: consul_handler.del_values(consul_key) consul_handler.clear_consul_cert() return
def consul_remove_group(*args, **kwargs): datacenter_domain = kwargs['datacenter']['qurom']['domain'] datacenter_port = kwargs['datacenter']['qurom']['port'] datacenter_cakey = kwargs['datacenter']['qurom']['cakey'] datacenter_cacert = kwargs['datacenter']['qurom']['cacert'] group_name = kwargs['group_name'] consul_handler = commConsul.CommConsul(datacenter_cacert, datacenter_cakey, LOG=logger) consul_handler.connect(datacenter_domain, datacenter_port) consul_key = 'deploy/deployGroup/%s' % group_name consul_handler.del_values(consul_key) consul_handler.clear_consul_cert() return
def consul_add_group(*args, **kwargs): group_name = args[0]['name'] datacenter_name = args[0]['datacenter'] datacenters = Datacenter.objects(name=datacenter_name) if not datacenters: logger.error('datacenter not exist.') return datacenter = datacenters[0] packages = Package.objects(service=args[0]['service'], version=args[0]['version']) if not packages: logger.error('service not exist.') return package = packages[0] datacenter = datacenters[0] consul_handler = commConsul.CommConsul(datacenter.qurom['cacert'], datacenter.qurom['cakey'], LOG=logger) consul_handler.connect(datacenter.qurom['domain'], datacenter.qurom['port']) consul_key = 'deploy/deployGroup/%s/status' % group_name consul_value = json.dumps({ 'service': args[0]['service'], 'cur_version': args[0]['version'], 'target_version': args[0]['version'], 'deploy_id': None, 'file_path': package['file_path'], 'verify': package['md5'][datacenter_name] if datacenter_name in package['md5'].keys() else package['md5']['source'], }) consul_handler.put_values(consul_key, consul_value) consul_handler.clear_consul_cert() return
def consul_remove_datacenter(*args, **kwargs): datacenter_domain = str(args[0]['qurom']['domain']) datacenter_port = int(args[0]['qurom']['port']) datacenter_cakey = args[0]['qurom']['cakey'] datacenter_cacert = args[0]['qurom']['cacert'] consul_handler = commConsul.CommConsul(datacenter_cacert, datacenter_cakey, LOG=logger) consul_handler.connect(datacenter_domain, datacenter_port) consul_key = 'deploy/dcInfo' consul_handler.del_values(consul_key) consul_key = 'deploy/agent/version' consul_handler.del_values(consul_key) consul_key = 'deploy/agent/authorization' consul_handler.del_values(consul_key) consul_handler.clear_consul_cert() return
def consul_sync_configs(*agrs, **kwargs): datacenter = kwargs['datacenter'] group_name = kwargs['group_name'] configs = kwargs['configs'] consul_handler = commConsul.CommConsul(datacenter['qurom']['cacert'], datacenter['qurom']['cakey'], LOG=logger) consul_handler.connect(datacenter['qurom']['domain'], datacenter['qurom']['port']) for config in configs: if config['consul_key']: consul_key = 'deploy/deployGroup/%s/config/%s' % ( group_name, config['consul_key']) consul_value = config['value'] consul_handler.put_values(consul_key, consul_value) consul_handler.clear_consul_cert() return
def consul_sync_config(*agrs, **kwargs): datacenter_domain = kwargs['datacenter']['qurom']['domain'] datacenter_port = kwargs['datacenter']['qurom']['port'] datacenter_cakey = kwargs['datacenter']['qurom']['cakey'] datacenter_cacert = kwargs['datacenter']['qurom']['cacert'] group_name = kwargs['group_name'] config_value = kwargs['config_value'] config_consul_key = kwargs['config_consul_key'] consul_handler = commConsul.CommConsul(datacenter_cacert, datacenter_cakey, LOG=logger) consul_handler.connect(datacenter_domain, datacenter_port) consul_key = 'deploy/deployGroup/%s/config/%s' % (group_name, config_consul_key) consul_value = config_value consul_handler.put_values(consul_key, consul_value) consul_handler.clear_consul_cert() return
def consul_sync_monitor(*args, **kwargs): datacenter_domain = kwargs['datacenter']['qurom']['domain'] datacenter_port = kwargs['datacenter']['qurom']['port'] datacenter_cakey = kwargs['datacenter']['qurom']['cakey'] datacenter_cacert = kwargs['datacenter']['qurom']['cacert'] group_name = kwargs['group_name'] monitors = kwargs['monitors'] consul_handler = commConsul.CommConsul(datacenter_cacert, datacenter_cakey, LOG=logger) consul_handler.connect(datacenter_domain, datacenter_port) consul_key = 'deploy/deployGroup/%s/monitors' % group_name consul_value = json.dumps(monitors) if monitors: consul_handler.put_values(consul_key, consul_value) else: consul_handler.del_values(consul_key) consul_handler.clear_consul_cert() return
def consul_sync_datacenter(*args, **kwargs): datacenter_domain = str(args[0]['qurom']['domain']) datacenter_port = int(args[0]['qurom']['port']) datacenter_cakey = args[0]['qurom']['cakey'] datacenter_cacert = args[0]['qurom']['cacert'] consul_handler = commConsul.CommConsul(datacenter_cacert, datacenter_cakey, LOG=logger) consul_handler.connect(datacenter_domain, datacenter_port) consul_key = 'deploy/dcInfo' consul_value = json.dumps({ 'name': args[0]['name'], 'envType': args[0]['env'], 'deployRegion': args[0]['deploy']['region'], 'deployBucket': args[0]['deploy']['bucket'] }) consul_handler.put_values(consul_key, consul_value) consul_key = 'deploy/agent/version' consul_value = json.dumps({ 'version': args[0]['agent']['version'], 'file_path': args[0]['agent']['file_path'] }) consul_handler.put_values(consul_key, consul_value) consul_key = 'deploy/agent/authorization' consul_value = json.dumps({ 'access_key': args[0]['agent']['secret_access_key'], 'access_id': args[0]['agent']['access_key_id'] }) consul_handler.put_values(consul_key, consul_value) consul_handler.clear_consul_cert() return