示例#1
0
def update_workload():
    try:
        workloads_data = json.loads(request.data)

        old_workload = get_workload(json.dumps(workloads_data['old']))
        new_workload = get_workload(json.dumps(workloads_data['new']))
        workload_pickler = WorkloadPickler()
        workload_pickler.update(old_workload, new_workload)
    except Exception as e:
        response_json = {"success": False, "error": str(e)}
        return Response(json.dumps(response_json),
                        status=500,
                        mimetype='application/json')

    response_json = {"success": True, "error": None}
    return Response(json.dumps(response_json),
                    status=200,
                    mimetype='application/json')
示例#2
0
def delete_workload():
    try:
        workload_data = str(request.data, 'utf-8')
        workload = get_workload(workload_data)
        workload_pickler = WorkloadPickler()
        workload_pickler.delete(workload)
    except Exception as e:
        response_json = {"success": False, "error": str(e)}
        return Response(json.dumps(response_json),
                        status=500,
                        mimetype='application/json')

    response_json = {"success": True, "error": None}
    return Response(json.dumps(response_json),
                    status=200,
                    mimetype='application/json')
示例#3
0
    def test_json_dec(self):
        s = '{"username": "******", "password": "******", "domain": null}'
        credentials = get_credentials(s)
        self.assertEqual(credentials.domain, None)

        s = r'{"mount_point_name": "C:\\", "size": 1024}'
        mount_point = get_mount_point(s)
        self.assertEqual(int(mount_point.size), 1024)

        s = '{"ip": "127.0.0.1", "credentials": {"username": "******", "password": "******", "domain": null},' \
            r' "storage": [{"mount_point_name": "C:\\", "size": 1024}]}'
        workload = get_workload(s)
        self.assertEqual(workload.ip, "127.0.0.1")
        self.assertEqual(workload.storage[0].size, 1024)

        s = '{"cloud_type": "AWS", ' \
            '"cloud_credentials": {"username": "******", "password": "******", "domain": null}, ' \
            '"target_vm": {"ip": "127.0.0.1", ' \
            '"credentials": {"username": "******", "password": "******", "domain": null}, ' \
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}}'
        target = get_migration_target(s)
        self.assertEqual(target.cloud_type, CloudType.AWS)
        self.assertEqual(target.target_vm.ip, "127.0.0.1")

        s = r'{"mount_points": [{"mount_point_name": "C:\\", "size": 1024}], ' \
            '"source": {"ip": "127.0.0.1", ' \
            '"credentials": {"username": "******", "password": "******", "domain": null}, ' \
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}, ' \
            '"migration_target": {"cloud_type":  "AWS", ' \
            '"cloud_credentials": {"username": "******", "password": "******", "domain": null}, ' \
            '"target_vm": {"ip": "127.0.0.1", ' \
            '"credentials": {"username": "******", "password": "******", "domain": null}, ' \
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}}, ' \
            '"migration_state": "RUNNING"}'
        migration = get_migration(s)
        self.assertEqual(migration.migration_state, MigrationState.RUNNING)
        self.assertEqual(migration.source.credentials.domain, None)
示例#4
0
 def get_serializable(self, s: str) -> Workload:
     return get_workload(s)