def save(self, session=None): if session is None: session = db.api.get_connection() client = session.client path = self.etcd_path(self.uuid) if self.path_already_exist(client, path): raise exception.ComputeNodeAlreadyExists(field='UUID', value=self.uuid) client.write(path, json.dump_as_bytes(self.as_dict())) return
def create_compute_node(self, context, values): # ensure defaults are present for new compute nodes if not values.get('uuid'): values['uuid'] = uuidutils.generate_uuid() compute_node = models.ComputeNode() compute_node.update(values) try: compute_node.save() except db_exc.DBDuplicateEntry: raise exception.ComputeNodeAlreadyExists( field='UUID', value=values['uuid']) return compute_node