def start(self, **post): if post: self._validate_start_post_data(post) creds = cherrypy.session.get('credentials') image = Images.first(id=post['image.id']) instance_type = self._get_instance_type(post) self._validate_start_args(image, instance_type) vm = VirtualMachines.new(status="new") if VirtualMachines.add(vm): if not vm.start_instance(image, instance_type, creds): cherrypy.session['flash'] = 'The virtual machine could not be started.' raise cherrypy.HTTPRedirect("/virtual_machines") else: cherrypy.session['flash'] = 'Missing image id.' raise cherrypy.HTTPRedirect("/virtual_machines")
def POST(self): # TODO Check if the ip already has an assigned VM # We might have to figure a way to generate a unique id on the VM side vm = VirtualMachines.new(ip=cherrypy.request.remote.ip) VirtualMachines.add(vm) return vm.to_dict()