def _resolve_vm(request): """Function given a request works out the VM we are talking about and whether the current user actually has permission to do stuff to it. Also returns the internal ID for the user, as well as the VM. """ actor_id = None vm_id = None try: actor_id = server.get_user_id_from_name(request.authenticated_userid) except: #OK, it must be an agent or an internal call. pass try: vm_id = (request.matchdict['id'] if 'id' in request.matchdict else server.get_server_id_from_name(request.matchdict['name'])) except: #Presumably because there is no such VM raise HTTPNotFound() if (request.has_permission('act') or server.check_ownership(vm_id, actor_id)): return vm_id, actor_id else: raise HTTPUnauthorized()
def test_get_server_id_from_dupe(self): """I'm not sure what the original thinking was, but the schema allows me to create 2 servers with the same name, in which case I want the newest one back when I search. """ artifact1 = self.my_create_appliance("dupe") self.assertEqual(s.get_server_id_from_name("dupe"), artifact1) #In an earlier bug an arbitrary server was returned. Hard to #test reliably for this situation. artifact2 = self.my_create_appliance("dupe") self.assertNotEqual(artifact2, artifact1) self.assertEqual(s.get_server_id_from_name("dupe"), artifact2) artifact3 = self.my_create_appliance("dupe") self.assertEqual(s.get_server_id_from_name("dupe"), artifact3)
def _resolve_vm(request): """Function given a request works out the VM we are talking about and whether the current user actually has permission to do stuff to it. Also returns the internal ID for the user, as well as the VM. """ actor_id = None vm_id = None try: actor_id = server.get_user_id_from_name(request.authenticated_userid) except: # OK, it must be an agent or an internal call. pass try: vm_id = ( request.matchdict["id"] if "id" in request.matchdict else server.get_server_id_from_name(request.matchdict["name"]) ) except: # Presumably because there is no such VM raise HTTPNotFound() if request.has_permission("act") or server.check_ownership(vm_id, actor_id): return vm_id, actor_id else: raise HTTPUnauthorized()
def test_get_server_id_from_name(self): artifact_id = self.my_create_appliance("getname") returned_id = s.get_server_id_from_name("getname") self.assertEqual(artifact_id, returned_id)