Ejemplo n.º 1
0
def list_object(provider, className, counter, total_requests, total_failures):
    try:
        start_time = datetime.now()
        print "find", counter
        test_list = CGCollection(className)
        # test_list.load(provider, {"skip":100})
        total_requests +=1
        test_list.load(provider)
        print "found", len(test_list.collection)
        print "time for request",(datetime.now() - start_time)
        skip_count = 1
        # while len(test_list.collection) %100 == 0 and len(test_list.collection):
        #     test_list = CGCollection(className)
        #     total_requests +=1
        #     time.sleep(1)
        #     test_list.load(provider, {"skip":100*skip_count})
        #     skip_count += 1
        #     print "found", len(test_list.collection),skip_count
        print "\n"
        print "total REQUESTS of instance: ",total_requests
        print "total FAILURES of instance: ", total_failures
        print "\n\n"
        return (total_requests, total_failures)
    except Exception as e:
        total_failures += 1
        print e, total_failures
        print "\n"
        print "total REQUESTS of instance: ",total_requests
        print "total FAILURES of instance: ", total_failures
        print "\n\n"
        return (total_requests, total_failures)
 def get_app_user_profile_by_username(self, userName):
     if not userName:
         raise Exception("Invalid username")
     profiles = CGCollection(self.app_user_profiles_string);
     profiles.load(self.provider, query={'app_user_name':userName})
     print "\nProfiles count", len(profiles.collection)
     if not profiles.collection:
         print "No users with user name: ",userName
         raise Exception("Invalid user")
     user = filter(lambda active_user: active_user.get('isDeleted') == False, profiles.collection)
     print "this is the user list", user
     return user[0].to_dict()
    def list_app_tenants(self, appid):
        if not appid:
            print "app id is not present"
            raise Exception("App id is not present")
        tenants = CGCollection("%s" % self.tenant_profiles_string)
        tenants.load(self.provider,{"clientId":appid})

        if (len(tenants.collection) == 0):
            return None
        tenants = json.loads(tenants.to_json())
        # tenants = [t.to_dict for t in tenants.collection]
        print "these are the tenants fetched",tenants
        return tenants
    def list_app_tenant_users(self, appid, tenantid):
        if not appid:
            print "app id is not present"
            raise Exception("App id not present")
        if not tenantid:
            print "tenant id is not present"
            raise Exception("Tenant id not present")
        users = CGCollection("%s" % self.app_user_profiles_string)
        users.load(self.provider, {"tenantId":tenantid, "clientId":appid})

        if (len(users.collection) == 0):
            return None
        print "test of json: ",users.to_json()
        users = json.loads(users.to_json())
        # users = [t.to_json for t in users.collection]
        print "these are the users fetched", users
        return users
    def activate_cg_user(self, activation_code):
        response = self.authManager._activate_user(activation_code)

        if response.status_code == 200:
            profile = CGCollection(self.user_profiles_string);
            provider = CloudgustDataProvider(self.appServer, self.appServerId, self.appServerKey, self.tenantId, self.userId, self.userKey)
            print response.text
            profile.load(provider, {"userName":response.text})
            print profile
            if profile:
                if not profile.collection:
                    self.logger.warning("No user with user name", extra={"userName":response.text})
                    raise Exception("Invalid user")
                user = filter(lambda active_user: active_user.get('isDeleted') == False, profile.collection)
                self.logger.info("this is the profile needed", extra={"userData":str(user[0])})
                return user[0].to_dict()
            else:
                raise Exception("no user")
        else:
            raise Exception(response.text)