def updateTasks(self, id, params): working_dir = self.model('setting').get(constants.PluginSettings.STARCLUSTER_WORK_DIRECTORY) configurationFilePath = os.path.join(working_dir, id.__str__()) # build cluster status indexed by task clusterMap = {} for cluster in ec2_controller.list_clusters(configurationFilePath): clusterMap[cluster['name']] = { "status": cluster['state'], "url" : "http://" + cluster['dns'] } # Build task map taskMap = {} for task in self.find({ "parentType": "folder", "parentId": id }): taskMap["%s_%s" % (task['task'], task['_id'])] = task # Update tasks status and URL if need be for id in taskMap: task = self.model('task', 'ec2_cloud').load(taskMap[id]['_id'], user=self.getCurrentUser()) if id in clusterMap: task['status'] = constants.CloudTaskStatus.RUNNING if clusterMap[id]["status"] == 'running' else constants.CloudTaskStatus.PENDING task['url'] = clusterMap[id]["url"] else: task['status'] = constants.CloudTaskStatus.READY print "Update task", id self.model('task', 'ec2_cloud').updateTask(task)
def listClusters(self, id, params): working_dir = self.model('setting').get(constants.PluginSettings.STARCLUSTER_WORK_DIRECTORY) configurationFilePath = os.path.join(working_dir, id) # Make sure user as access to project # FIXME return ec2_controller.list_clusters(configurationFilePath)