]> git.basschouten.com Git - openhab-addons.git/blob
c27faa11f350ffeb9fccd1612cea776962604390
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.freeboxos.internal.api.rest;
14
15 import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.THING_VM;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
19 import org.openhab.binding.freeboxos.internal.api.Response;
20
21 import inet.ipaddr.mac.MACAddress;
22
23 /**
24  * The {@link VmManager} is the Java class used to handle api requests related to virtual machines
25  *
26  * @author GaĆ«l L'hopital - Initial contribution
27  */
28 @NonNullByDefault
29 public class VmManager extends ListableRest<VmManager.VirtualMachine, VmManager.VirtualMachineResponse> {
30
31     protected class VirtualMachineResponse extends Response<VirtualMachine> {
32     }
33
34     public enum Status {
35         STOPPED,
36         RUNNING,
37         UNKNOWN
38     }
39
40     public static record VirtualMachine(int id, String name, MACAddress mac, Status status) {
41     }
42
43     public VmManager(FreeboxOsSession session) throws FreeboxException {
44         super(session, LoginManager.Permission.VM, VirtualMachineResponse.class,
45                 session.getUriBuilder().path(THING_VM));
46     }
47
48     public void power(int vmId, boolean startIt) throws FreeboxException {
49         post(Integer.toString(vmId), startIt ? "start" : "powerbutton");
50     }
51 }