Exemplo n.º 1
0
    def populate_provider_choices(self, request, context):
        cnext_tuples = []
        self.check_list = []
        for role in request.user.roles:
            for policy in role.policy:
                if ((policy.provider).lower(), (policy.region).lower(),
                        policy.allowed) in self.check_list:
                    pass
                else:
                    self.check_list.append(
                        ((policy.provider).lower(), (policy.region).lower(),
                         policy.allowed))
        policy_allow = [[
            i.roletype if i.roletype == "Tenant Admin" else "Member"
        ] for i in request.user.roles]
        if "Tenant Admin" in policy_allow[0]:
            cnext_provider = capi.providers(request)
            if "provider" in context:
                cprovider = context["provider"].lower()
                cnext_provider = list( filter((lambda x: x.__dict__["provider"].lower() \
                                                == cprovider ), cnext_provider ))
            for cprovider in cnext_provider:
                cnid = cprovider.__dict__['provider']
                cnext_tuples.append((cnid, cprovider))
            if "provider" not in context:
                if cnext_tuples:
                    cnext_tuples.insert(0, ("", _("Select Provider")))
                else:
                    cnext_tuples.insert(0, ("", _("No provider available")))
            return cnext_tuples
        else:
            pro_check_list = []
            pro_list = []
            if "provider" in context:
                cprovider = context["provider"].lower()
                for pro in self.check_list:
                    print pro[0] in self.check_list
                    if (pro[0] == cprovider) & (pro[0] not in pro_check_list):
                        pro_check_list.append(pro)
                    else:
                        pass
            if pro_check_list:
                self.check_list = pro_check_list
            for provider in self.check_list:
                if "Create Instance" in provider[2]:
                    pro_list.append(provider[0])
                else:
                    pass
            pro_list = list(set(pro_list))
            print pro_list
            for pro in pro_list:
                cnext_tuples.append((pro, capi.Provider(pro)))

            if "provider" not in context:
                if cnext_tuples:
                    cnext_tuples.insert(0, ("", _("Select Provider")))
                else:
                    cnext_tuples.insert(0, ("", _("No provider available")))
            return cnext_tuples
    def populate_provider_choices(self, request, context):
        cnext_tuples  = []
        self.check_list= []
        for role in request.user.roles:
            for policy in role.policy:
                if ((policy.provider).lower(),(policy.region).lower(),policy.allowed) in self.check_list:
                    pass
                else:
                    self.check_list.append(((policy.provider).lower(),(policy.region).lower(),policy.allowed))
        policy_allow = [[i.roletype if i.roletype == "Tenant Admin" else "Member"] for i in request.user.roles]            
        if "Tenant Admin" in policy_allow[0]:
            cnext_provider = capi.providers(request)
            if "provider" in context:
                cprovider = context["provider"].lower()
                cnext_provider = list( filter((lambda x: x.__dict__["provider"].lower() \
                                                == cprovider ), cnext_provider ))
            for cprovider in cnext_provider:
                cnid = cprovider.__dict__['provider']
                cnext_tuples.append((cnid, cprovider))
            if "provider" not in context:
                if cnext_tuples:
                    cnext_tuples.insert(0, ("", _("Select Provider")))
                else:
                    cnext_tuples.insert(0, ("", _("No provider available")))
            return cnext_tuples
        else:
            pro_check_list =[]
            pro_list = []
            if "provider" in context:
                cprovider = context["provider"].lower()
                for pro in self.check_list:
                    print pro[0] in self.check_list
                    if ( pro[0] == cprovider) &( pro[0]  not in pro_check_list) :
                        pro_check_list.append(pro)
                    else:
                        pass
            if pro_check_list:
                self.check_list = pro_check_list
            for provider in self.check_list:
                if "Create Instance" in provider[2]:
                    pro_list.append(provider[0])
                else:
                    pass
            pro_list = list(set(pro_list))
            print pro_list
            for pro in pro_list:
                cnext_tuples.append((pro,capi.Provider(pro)))

            if "provider" not in context:
                if cnext_tuples:
                    cnext_tuples.insert(0, ("", _("Select Provider")))
                else:
                    cnext_tuples.insert(0, ("", _("No provider available")))
            return cnext_tuples
Exemplo n.º 3
0
 def __init__(self, request, *args, **kwargs):
     forms.SelfHandlingForm.__init__(self, request, *args, **kwargs)
     provider_list = api.providers(self.request)
     region_list = api.region(self.request)
     p = [("", _("Select Provider"))]
     for provider in provider_list:
         if provider.provider in provider_keypairs_choices:
             p.append((provider.provider.lower(),provider.provider))
     t = tuple(p)
     tuple_providers = t
     self.fields['key_provider_list'].choices = tuple_providers
     r = [("", _("Select Region"))]
     for region in region_list:
         if region.name in region_keypairs_choices:
             r.append((region.name,Regionlist(region.provider,region.name)))
     r = tuple(r)
     tuple_regions = r
     self.fields['key_region_list'].choices = tuple_regions
Exemplo n.º 4
0
 def populate_providers_choices(self, request, context):
     cnext_tuples  = []
     status = []
     for role in request.user.roles:
         for policy in role.policy:
             if policy.cloudid.platform == "Cnext":
                 status.append("True")
             else:
                 pass
     if "True" in status:
         cnext_provider = capi.providers(request)        
         for cprovider in cnext_provider:
             cnid = cprovider.__dict__['provider']
             cnext_tuples.append((cnid, cprovider))
         cnext_tuples.insert(0, ("", _("Select Provider")))
         return cnext_tuples
     else:
         return cnext_tuples
Exemplo n.º 5
0
 def __init__(self, request, *args, **kwargs):
     forms.SelfHandlingForm.__init__(self, request, *args, **kwargs)
     provider_list = api.providers(self.request)
     region_list = api.region(self.request)
     p = [("", _("Select Provider"))]
     for provider in provider_list:
         if provider.provider in provider_sg_choices:
             p.append((provider.provider.lower(), provider.provider))
     t = tuple(p)
     tuple_providers = t
     self.fields['key_provider_list'].choices = tuple_providers
     r = [("", _("Select Region"))]
     for region in region_list:
         if region.name in region_sg_choices:
             r.append((region.name,Regionlist(region.provider.lower(), region.name)))
     r = tuple(r)
     tuple_regions = r
     self.fields['key_region_list'].choices = tuple_regions
Exemplo n.º 6
0
 def get_context_data(self, **kwargs):
     context = super(IndexView, self).get_context_data()
     context["provider"] = api.providers(self.request)
     context["region"] = api.region(self.request)
     return context
Exemplo n.º 7
0
 def get_context_data(self):
     context = super(IndexView, self).get_context_data()
     context["provider"] = api.providers(self.request)
     context["region"] = api.region(self.request)
     return context