def delete(cls, ctx, profile_id): obj = cls.load(ctx, profile_id=profile_id) cluster_id = obj.properties.get(obj.HOST_CLUSTER, None) if cluster_id: db_api.cluster_remove_dependents(ctx, cluster_id, profile_id) node_id = obj.properties.get(obj.HOST_NODE, None) if node_id: db_api.node_remove_dependents(ctx, node_id, profile_id, 'profile') super(DockerProfile, cls).delete(ctx, profile_id)
def test_node_remove_profile_dependents(self): node_id = 'host_node' dependents = {'profiles': ['P1', 'P2']} node = shared.create_node(self.ctx, None, self.profile, id=node_id, dependents=dependents) db_api.node_remove_dependents(self.ctx, node_id, 'P1', 'profile') node = db_api.node_get(self.ctx, node_id) dependents = node.dependents self.assertEqual({'profiles': ['P2']}, dependents) db_api.node_remove_dependents(self.ctx, node_id, 'P2', 'profile') node = db_api.node_get(self.ctx, node_id) dependents = node.dependents self.assertEqual({}, dependents)
def do_delete(self, obj): """Delete a container node. :param obj: The node object representing the container. :returns: `None` """ if not obj.physical_id: return try: self.docker(obj).container_delete(obj.physical_id) except exc.InternalError as ex: raise exc.EResourceDeletion(type='container', id=obj.physical_id, message=six.text_type(ex)) ctx = context.get_admin_context() db_api.node_remove_dependents(ctx, self.host.id, obj.id) return