def save_activation(self, slug, activation):
     if os.getenv("CS_DEBUG"):
         print slug, activation
     r = self.client.put('activations/%s' % slug, activation)
     if r.status_code == 200:
         return Success({'message': 'Saved activation %s' % slug})
     return create_error(r)
 def activate_service(self, activation):
     r = self.client.post('activations', activation)
     if r.status_code == 201:
         if os.getenv("CS_DEBUG"):
             print r.headers
         slug = r.headers['Location']
         return Success({'message': 'Created activation %s' % slug, 'slug': slug})
     return create_error(r)
    def get_service_of_type(self, service_type, service_id):
        r = self.client.get_as_json("services", {'typeExpr': service_type, 'idExpr': service_id})
        if "services" in r:
            if len(r["services"]) == 0:
                return Error({"error": "Service of type %s with ID %s not found" % (service_type, service_id)})
            return Success({"service": Service(self.client, r["services"][0])})

        return create_error(r)
    def query(self, query, params={}, depth=0):
        args = {'query': query, 'params': params}
        path = DEFAULT_CYPHER_PATH
        if depth > 0:
            path = C12E_GRF_PATH
            args['depth'] = depth

        r = self.client.post(path, args)
        if r.status_code == 200:
            return Success({'result': r.json()})

        return create_error(r)
 def drop_activation(self, slug):
     r = self.client.delete('activations/%s' % slug)
     if r.status_code == 200:
         return Success({'message': 'Activation %s dropped successfully' % slug})
     return create_error(r)
 def resume_activation(self, slug):
     r = self.client.put('activations/%s/state' % slug, "enabled")
     if r.status_code // 100 == 2:
         return Success({'message': 'resumed activation %s' % slug})
     return create_error(r)