Ejemplo n.º 1
0
 def __init__(self, request, *args, **kwargs):
     super(ManagePoliciesForm, self).__init__(request, *args, **kwargs)
     cluster_policies = senlin.cluster_policy_list(self.request, kwargs["initial"]["cluster_id"], {})
     cluster_policies_ids = [policy.id for policy in cluster_policies]
     policies = senlin.policy_list(self.request)
     available_policies = [(policy.id, policy.name) for policy in policies if policy.id not in cluster_policies_ids]
     self.fields["policies"].choices = [("", _("Select Policy"))] + available_policies
Ejemplo n.º 2
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     table = ClustersTable(self.request)
     cluster = self.get_object()
     policies = senlin.cluster_policy_list(self.request, self.kwargs["cluster_id"], {})
     cluster.policies = policies
     context["actions"] = table.render_row_actions(cluster)
     context["cluster"] = cluster
     return context
Ejemplo n.º 3
0
 def __init__(self, request, *args, **kwargs):
     super(ManagePoliciesForm, self).__init__(request, *args, **kwargs)
     cluster_policies = senlin.cluster_policy_list(
         self.request, kwargs['initial']['cluster_id'], {})
     cluster_policies_ids = [policy.id for policy in cluster_policies]
     policies = senlin.policy_list(self.request)[0]
     available_policies = [(policy.id, policy.name) for policy in policies
                           if policy.id not in cluster_policies_ids]
     self.fields['policies'].choices = (
         [("", _("Select Policy"))] + available_policies)
Ejemplo n.º 4
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     table = ClustersTable(self.request)
     cluster = self.get_object()
     policies = senlin.cluster_policy_list(
         self.request, self.kwargs['cluster_id'], {})
     cluster.policies = policies
     context["actions"] = table.render_row_actions(cluster)
     context["cluster"] = cluster
     return context
Ejemplo n.º 5
0
    def put(self, request, cluster_id, action):
        if action == "policy":
            """Update policies for the cluster."""
            params = request.DATA

            new_attach_ids = params["ids"]
            old_attached = senlin.cluster_policy_list(request, cluster_id, {})

            # Extract policies should be detached and execute
            for policy in old_attached:
                should_detach = True
                for new_id in new_attach_ids:
                    if new_id == policy.policy_id:
                        # This policy is already attached.
                        should_detach = False
                        break
                if should_detach:
                    # If policy is not exist in new policies,
                    # it should be removed
                    senlin.cluster_detach_policy(request, cluster_id,
                                                 policy.policy_id)

            # Extract policies should be attached and execute
            for new_id in new_attach_ids:
                should_attach = True
                for policy in old_attached:
                    if new_id == policy.policy_id:
                        # This policy is already attached.
                        should_attach = False
                        break
                if should_attach:
                    # If policy is not exist in old policies,
                    # it should be added
                    senlin.cluster_attach_policy(request, cluster_id, new_id,
                                                 {})

            return rest_utils.CreatedResponse(
                '/api/senlin/clusters/%s/policy' % cluster_id)
        elif action == "scale-in":
            count = request.DATA.get("count") or None
            return senlin.cluster_scale_in(request, cluster_id, count)
        elif action == "scale-out":
            count = request.DATA.get("count") or None
            return senlin.cluster_scale_out(request, cluster_id, count)
        elif action == "resize":
            params = request.DATA
            return senlin.cluster_resize(request, cluster_id, **params)
Ejemplo n.º 6
0
    def get(self, request, cluster_id, action):
        if action == "policy":
            """Get policies of a single cluster with the cluster id.

            The following get parameters may be passed in the GET

            :param cluster_id: the id of the cluster

            The result is a cluster object.
            """
            policies = senlin.cluster_policy_list(request, cluster_id, {})

            return {
                'items': [p.to_dict() for p in policies],
            }
        elif action == "":
            return None
Ejemplo n.º 7
0
 def get_data(self):
     policies = senlin.cluster_policy_list(
         self.request, self.kwargs['cluster_id'], {})
     return policies
Ejemplo n.º 8
0
 def get_data(self):
     policies = senlin.cluster_policy_list(
         self.request, self.kwargs['cluster_id'], {})
     return policies