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_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 run_playbook(self, o, fields): tStart = time.time() run_template_ssh(self.template_name, fields) logger.info("playbook execution time %d" % int(time.time()-tStart))
def run_playbook(self, o, fields): tStart = time.time() run_template_ssh(self.template_name, fields) logger.info("playbook execution time %d" % int(time.time() - tStart))
def run_playbook(self, o, fields, template_name=None): if not template_name: template_name = self.template_name tStart = time.time() run_template_ssh(template_name, fields) logger.info("playbook execution time %d" % int(time.time()-tStart))
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()