Beispiel #1
0
def addMachine():
    try:
        machine = Machine()
        machine.fromJson(request.json)

        result = machine.save()
        if (result["status"] == "ok"):
            return Response.Ok("successfully inserted", result["id"])
        else:
            return Response.Error(payload=result["message"])
    except Exception, e:
        return jsonify(status='ERROR', message=str(e))
 def create_lab(self, lab_request: LabCreateRequest):
     id = str(uuid.uuid4())
     worker = self.workers_selector.next()
     template = self.lab_templates_service.get_template_by_lab_name(lab_request.lab_template_name)
     lab = Lab(
         id,
         lab_request.lab_name,
         worker.worker_id,
         lab_request.user_id,
         datetime.datetime.now(),
         template.id,
         lab_request.start_date,
         lab_request.expiration_date,
         lab_request.description,
         len(lab_request.machines)
     )
     self.labs_repository.insert(lab)
     for i, machine in enumerate(lab_request.machines[:MAX_VM_COUNT]):
         machine_id = uuid.uuid4()
         self.machines_repository.insert(Machine(
             machine_id,
             id,
             'node-{}'.format(i+1),
             machine
         ))
     self.__send_to_worker(worker, id, template.code_name, min(len(lab_request.machines), MAX_VM_COUNT), lab_request.start_date, lab_request.expiration_date)
     return id
Beispiel #3
0
def deleteMachine():
    postData = request.json
    result = Machine.delete(postData["_id"])
    if (result):
        return Response.Ok()
    else:
        return Response.Error(result)
Beispiel #4
0
 def post(self):
     data = request.json
     machine = Machine(**data)
     db.session.add(machine)
     db.session.commit()
     response = jsonify({})
     response.status_code = 201
     return response
Beispiel #5
0
 def test_create_machine(self):
     mach = Machine(
         'foo.example.com',
         ip_addresses=['192.168.1.100, 192.168.2.100'],
         net_interfaces=['eth0', 'eth1'],
         disk=100,
         ram=2048,
         cores=4)
     db.session.add(mach)
     db.session.commit()
     self.assertEqual(1, mach.machine_id)
Beispiel #6
0
def test_get_lab_details_should_return_lab_details(tests_setup):
    tests_setup.workers_service.get_worker.return_value = tests_setup.workers[
        1]
    tests_setup.worker2_client.get_vm_details.return_value = {
        "lab_id":
        "id2",
        "status":
        "running",
        "machines": [{
            "name": "node-1",
            "status": "running",
            "rdp_port": "1111",
            "ssh_port": "2222",
            "login": "******",
            "password": "******"
        }]
    }

    tests_setup.machines_repository.get_by_lab_id.return_value = [
        Machine("machine_id", "id2", "node-1", "machine_name")
    ]

    tests_setup.labs_repository.get_by_id.return_value = tests_setup.labs[1]

    sut = LabsService(tests_setup.labs_repository, tests_setup.worker_selector,
                      tests_setup.worker_client_factory,
                      tests_setup.workers_service,
                      tests_setup.machines_repository,
                      tests_setup.lab_templates_service)
    result = sut.get_lab_details("id2")

    assert result == {
        "lab_id":
        "id2",
        "status":
        "running",
        "lab_name":
        "name",
        "machines": [{
            "id": "node-1",
            "name": "machine_name",
            "status": "running",
            "rdp_address": "HOST2:1111",
            "ssh_address": "HOST2:2222",
            "login": "******",
            "password": "******"
        }]
    }
Beispiel #7
0
def create_machine(cluster_id, name, ip, instance_type, tags):
    new_machine = Machine(cluster_id, name, ip, instance_type, tags)
    machine_rec = new_machine.json()
    MongoConnection().get_machine_collection().insert_one(machine_rec)
    return new_machine.machine_id
Beispiel #8
0
 def setUp(self):
     super(TestServiceModel, self).setUp()
     self.machine1 = Machine('foo1.example.com')
     self.machine2 = Machine('foo2.example.com')
Beispiel #9
0
 def test_todict_returns_dict(self):
     mach = Machine('foo.example.com')
     self.assertEqual(TEST_MACHINE, mach.to_dict())
Beispiel #10
0
def get(id):
    machine = Machine(id)
    return jsonify(machine.toJson())
Beispiel #11
0
def listMachine():
    return jsonify(Machine.getAll())
Beispiel #12
0
 def get_by_lab_id(self, lab_id) -> [Machine]:
     with DbConnection(self.config) as con:
         result = con.execute(
             machines.select().where(machines.c.lab_id == lab_id))
         rows = result.fetchall()
         return [Machine(*r) for r in rows]