from paella.views.util import make_resource from paella.managers.wiki import WikiManager log = logging.getLogger(__name__) sitetext_path = os.path.join(MAIN_RESOURCE_ROOT, 'sitetext') def convert_range_to_datetime(start, end): "start and end are timestamps" start = datetime.fromtimestamp(float(start)) end = datetime.fromtimestamp(float(end)) return start, end @resource(permission='admin', **make_resource(sitetext_path, ident='name')) class SiteTextResource(BaseManagementResource): mgrclass = WikiManager def collection_post(self): request = self.request db = request.db name = request.json['name'] content = request.json['content'] #type = request.json.get('type', 'tutwiki') page = self.mgr.add_page(name, content) response = dict(data=page.serialize(), result='success') return response def collection_get(self): return [p.serialize() for p in self.mgr.query()]
from paella.views.util import make_resource log = logging.getLogger(__name__) # Machine POST Actions # # submit - submit a brand new machine # # install - sets a machine to be installed # # stage_over - tells paella server that debian-installer has completed # # @resource(**make_resource(os.path.join(MAIN_RESOURCE_ROOT, 'machines'), ident='uuid')) class MachineResource(BaseMachineResource): def collection_get(self): return dict(data=self.mgr.list_machines(names=True)) # recipe is by name # if recipe is not None, we retrieve it from # the database. def _submit_machine(self, data): # FIXME machine parameter must go if 'name' in data: name = data['name'] else: name = data['machine'] if name in self.mgr.list_machines(): msg = "A machine named %s already exists." % name
def delete(self): name = self.request.matchdict['name'] recipe = self.mgr.get_by_name(name) self.mgr.delete(recipe) return dict(result='success') def put(self): recipe = self.mgr.get(self.request.json.get('id')) log.info('json is %s' % self.request.json) content = self.request.json.get('content') log.info('content is %s' % content) self.mgr.update(recipe, content=content) return dict(result='success') @resource(**make_resource(os.path.join(MAIN_RESOURCE_ROOT, 'recipes'), ident='name')) class RecipeResource(BaseRecipeResource): mgrclass = PartmanRecipeManager @resource(**make_resource(os.path.join(MAIN_RESOURCE_ROOT, 'raidrecipes'), ident='name')) class RaidRecipeResource(BaseRecipeResource): mgrclass = PartmanRaidRecipeManager