def get_next_index(cls, context, cluster_id): return db_api.cluster_next_index(context, cluster_id)
def _create_nodes(self, count): """Utility method for node creation. :param count: Number of nodes to create. :returns: A tuple comprised of the result and reason. """ if count == 0: return self.RES_OK, '' placement = self.data.get('placement', None) nodes = [] child = [] for m in range(count): index = db_api.cluster_next_index(self.context, self.cluster.id) kwargs = { 'index': index, 'metadata': {}, 'user': self.cluster.user, 'project': self.cluster.project, 'domain': self.cluster.domain, } if placement is not None: # We assume placement is a list kwargs['data'] = {'placement': placement['placements'][m]} name = 'node-%s-%003d' % (self.cluster.id[:8], index) node = node_mod.Node(name, self.cluster.profile_id, self.cluster.id, context=self.context, **kwargs) node.store(self.context) nodes.append(node) kwargs = { 'name': 'node_create_%s' % node.id[:8], 'cause': base.CAUSE_DERIVED, } action_id = base.Action.create(self.context, node.id, consts.NODE_CREATE, **kwargs) child.append(action_id) if child: # Build dependency and make the new action ready db_api.dependency_add(self.context, [a for a in child], self.id) for cid in child: db_api.action_update(self.context, cid, {'status': base.Action.READY}) dispatcher.start_action(action_id=cid) # Wait for cluster creation to complete res, reason = self._wait_for_dependents() if res == self.RES_OK: nodes_added = [n.id for n in nodes] self.outputs['nodes_added'] = nodes_added creation = self.data.get('creation', {}) creation['nodes'] = nodes_added self.data['creation'] = creation for node in nodes: self.cluster.add_node(node) else: reason = _('Failed in creating nodes.') return res, reason return self.RES_OK, ''
def _create_nodes(self, count): """Utility method for node creation. :param count: Number of nodes to create. :returns: A tuple comprised of the result and reason. """ if count == 0: return self.RES_OK, '' placement = self.data.get('placement', None) nodes = [] for m in range(count): index = db_api.cluster_next_index(self.context, self.cluster.id) kwargs = { 'index': index, 'metadata': {}, 'user': self.cluster.user, 'project': self.cluster.project, 'domain': self.cluster.domain, } if placement is not None: # We assume placement is a list kwargs['data'] = {'placement': placement[m]} name = 'node-%s-%003d' % (self.cluster.id[:8], index) node = node_mod.Node(name, self.cluster.profile_id, self.cluster.id, context=self.context, **kwargs) node.store(self.context) nodes.append(node) kwargs = { 'name': 'node_create_%s' % node.id[:8], 'cause': base.CAUSE_DERIVED, 'user': self.context.user, 'project': self.context.project, 'domain': self.context.domain, } action = base.Action(node.id, 'NODE_CREATE', **kwargs) action.store(self.context) # Build dependency and make the new action ready db_api.action_add_dependency(self.context, action.id, self.id) action.set_status(action.READY) dispatcher.start_action(action_id=action.id) if count > 0: # Wait for cluster creation to complete res, reason = self._wait_for_dependents() if res == self.RES_OK: self.outputs['nodes_added'] = [n.id for n in nodes] for node in nodes: self.cluster.add_node(node) return res, reason return self.RES_OK, ''