def sync_record(self, o): logger.info("sync'ing VCPETenant %s" % str(o)) sliver = self.get_sliver(o) if not sliver: self.defer_sync(o, "waiting on sliver") return service = o.sliver.slice.service if not service: # Ansible uses the service's keypair in order to SSH into the # instance. It would be bad if the slice had no service. raise Exception("Slice %s is not associated with a service" % sliver.slice.name) if not os.path.exists(self.service_key_name): raise Exception("Service key %s does not exist" % self.service_key_name) service_key = file(self.service_key_name).read() fields = { "sliver_name": sliver.name, "hostname": sliver.node.name, "instance_id": sliver.instance_id, "private_key": service_key, "ansible_tag": "vcpe_tenant_" + str(o.id) } if hasattr(o, "sync_attributes"): for attribute_name in o.sync_attributes: fields[attribute_name] = getattr(o, attribute_name) fields.update(self.get_extra_attributes(o)) ansible_hash = hashlib.md5(repr(sorted(fields.items()))).hexdigest() quick_update = (o.last_ansible_hash == ansible_hash) if quick_update: logger.info("quick_update triggered; skipping ansible recipe") else: tStart = time.time() run_template_ssh(self.template_name, fields) logger.info("playbook execution time %d" % int(time.time()-tStart)) if o.url_filter_enable: tStart = time.time() bbs = BBS(o.bbs_account, "123") bbs.sync(o.url_filter_level, o.users) if o.hpc_client_ip: logger.info("associate account %s with ip %s" % (o.bbs_account, o.hpc_client_ip)) bbs.associate(o.hpc_client_ip) else: logger.info("no hpc_client_ip to associate") logger.info("bbs update tiem %d" % int(time.time()-tStart)) o.last_ansible_hash = ansible_hash o.save()
def sync_fields(self, o, fields): # the super causes the playbook to be run super(SyncVSGTenant, self).sync_fields(o, fields) # now do all of our broadbandshield stuff... service = self.get_vcpe_service(o) if not service: # Ansible uses the service's keypair in order to SSH into the # instance. It would be bad if the slice had no service. raise Exception("Slice %s is not associated with a service" % instance.slice.name) # Make sure the slice is configured properly if (service != o.instance.slice.service): raise Exception("Slice %s is associated with some service that is not %s" % (str(instance.slice), str(service))) # only enable filtering if we have a subscriber object (see below) url_filter_enable = False # for attributes that come from CordSubscriberRoot if o.volt and o.volt.subscriber: url_filter_enable = o.volt.subscriber.url_filter_enable url_filter_level = o.volt.subscriber.url_filter_level url_filter_users = o.volt.subscriber.users if service.url_filter_kind == "broadbandshield": # disable url_filter if there are no bbs_addrs if url_filter_enable and (not fields.get("bbs_addrs",[])): logger.info("disabling url_filter because there are no bbs_addrs",extra=o.tologdict()) url_filter_enable = False if url_filter_enable: bbs_hostname = None if service.bbs_api_hostname and service.bbs_api_port: bbs_hostname = service.bbs_api_hostname else: # TODO: extract from slice bbs_hostname = "cordcompute01.onlab.us" if service.bbs_api_port: bbs_port = service.bbs_api_port else: bbs_port = 8018 if not bbs_hostname: logger.info("broadbandshield is not configured",extra=o.tologdict()) else: tStart = time.time() bbs = BBS(o.bbs_account, "123", bbs_hostname, bbs_port) bbs.sync(url_filter_level, url_filter_users) if o.hpc_client_ip: logger.info("associate account %s with ip %s" % (o.bbs_account, o.hpc_client_ip),extra=o.tologdict()) bbs.associate(o.hpc_client_ip) else: logger.info("no hpc_client_ip to associate",extra=o.tologdict()) logger.info("bbs update time %d" % int(time.time()-tStart),extra=o.tologdict())
def sync_record(self, o): logger.info("sync'ing VCPETenant %s" % str(o)) sliver = self.get_sliver(o) if not sliver: self.defer_sync(o, "waiting on sliver") return service = o.sliver.slice.service if not service: # Ansible uses the service's keypair in order to SSH into the # instance. It would be bad if the slice had no service. raise Exception("Slice %s is not associated with a service" % sliver.slice.name) if not os.path.exists(self.service_key_name): raise Exception("Service key %s does not exist" % self.service_key_name) service_key = file(self.service_key_name).read() fields = { "sliver_name": sliver.name, "hostname": sliver.node.name, "instance_id": sliver.instance_id, "private_key": service_key, "ansible_tag": "vcpe_tenant_" + str(o.id) } if hasattr(o, "sync_attributes"): for attribute_name in o.sync_attributes: fields[attribute_name] = getattr(o, attribute_name) fields.update(self.get_extra_attributes(o)) run_template_ssh(self.template_name, fields) if o.url_filter_enable: bbs = BBS(o.bbs_account, "123") bbs.sync(o.url_filter_level, o.users) o.save()
def sync_record(self, o): logger.info("sync'ing VCPETenant %s" % str(o)) sliver = self.get_sliver(o) if not sliver: self.defer_sync(o, "waiting on sliver") return service = o.sliver.slice.service if not service: # Ansible uses the service's keypair in order to SSH into the # instance. It would be bad if the slice had no service. raise Exception("Slice %s is not associated with a service" % sliver.slice.name) if not os.path.exists(self.service_key_name): raise Exception("Service key %s does not exist" % self.service_key_name) service_key = file(self.service_key_name).read() fields = { "sliver_name": sliver.name, "hostname": sliver.node.name, "instance_id": sliver.instance_id, "private_key": service_key, "ansible_tag": "vcpe_tenant_" + str(o.id) } if hasattr(o, "sync_attributes"): for attribute_name in o.sync_attributes: fields[attribute_name] = getattr(o, attribute_name) fields.update(self.get_extra_attributes(o)) ansible_hash = hashlib.md5(repr(sorted(fields.items()))).hexdigest() quick_update = (o.last_ansible_hash == ansible_hash) if quick_update: logger.info("quick_update triggered; skipping ansible recipe") else: tStart = time.time() run_template_ssh(self.template_name, fields) logger.info("playbook execution time %d" % int(time.time() - tStart)) if o.url_filter_enable: tStart = time.time() bbs = BBS(o.bbs_account, "123") bbs.sync(o.url_filter_level, o.users) if o.hpc_client_ip: logger.info("associate account %s with ip %s" % (o.bbs_account, o.hpc_client_ip)) bbs.associate(o.hpc_client_ip) else: logger.info("no hpc_client_ip to associate") logger.info("bbs update tiem %d" % int(time.time() - tStart)) o.last_ansible_hash = ansible_hash o.save()