Пример #1
0
    def test_altervm(self):
        """Test AlterVM"""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("cpu.count", "=", 1),
                Feature("memory.size", "=", 512, "M"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        radl = RADL()
        radl.add(
            system("s1", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("cpu.count", "=", 1),
                Feature("memory.size", "=", 512, "M"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("cpu.count", "=", 2),
                Feature("memory.size", "=", 1024, "M"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s1", 1))
        radl.add(deploy("s0", 1))

        radl_info = IM.AlterVM(infId, "0", str(radl), auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("cpu.count"), 2)
        self.assertEqual(
            parsed_radl_info.systems[0].getFeature('memory.size').getValue(
                'M'), 1024)

        radl = RADL()
        radl.add(
            system("s1", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("cpu.count", "=", 2),
                Feature("memory.size", "=", 1024, "M"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s1", 1))

        with self.assertRaises(Exception) as ex:
            IM.AlterVM(infId, "0", str(radl), auth0)
        self.assertEqual(str(ex.exception),
                         'Incorrect RADL no system with name s0 provided.')

        IM.DestroyInfrastructure(infId, auth0)
Пример #2
0
def RESTAlterVM(infid=None, vmid=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()

        if content_type:
            if "application/json" in content_type:
                radl_data = parse_radl_json(radl_data)
            elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                content_type = "text/plain"
            else:
                return return_error(415, "Unsupported Media Type %s" % content_type)

        vm_info = InfrastructureManager.AlterVM(infid, vmid, radl_data, auth)

        return format_output(vm_info, field_name="radl")
    except DeletedInfrastructureException as ex:
        return return_error(404, "Error modifying resources: " + str(ex))
    except IncorrectInfrastructureException as ex:
        return return_error(404, "Error modifying resources: " + str(ex))
    except UnauthorizedUserException as ex:
        return return_error(403, "Error modifying resources: " + str(ex))
    except DeletedVMException as ex:
        return return_error(404, "Error modifying resources: " + str(ex))
    except IncorrectVMException as ex:
        return return_error(404, "Error modifying resources: " + str(ex))
    except Exception as ex:
        logger.exception("Error modifying resources")
        return return_error(400, "Error modifying resources: " + str(ex))