Java tutorial
/** * Copyright (c) 2014 Marta Nabozny, Maciej Nabozny * * This file is part of OverCluster project. * * OverCluster is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package JavaCloud.Models; import JavaCloud.CoreException; import JavaCloud.Utils; import org.json.simple.JSONObject; public class VM { String address; String token; public int id; public String name; public String description; public String state; public Image base_image; public Template template; public VM(String address, String token, JSONObject vm_dict) { this.address = address; this.token = token; id = Integer.parseInt(vm_dict.get("id").toString()); name = vm_dict.get("name").toString(); description = vm_dict.get("description").toString(); state = vm_dict.get("state").toString(); base_image = new Image(address, token, (JSONObject) vm_dict.get("base_image")); template = new Template(address, token, (JSONObject) vm_dict.get("template")); // TODO: New variables } public String toString() { return name; } public void start() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/start/", object); } public void reset() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/reset/", object); } public void poweroff() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/poweroff/", object); } public void shutdown() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/shutdown/", object); } public void cleanup() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/cleanup/", object); } public void saveImage() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/save_image/", object); } public void cancelTasks() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); object.put("vm_id", id); Utils.request(address, "/api/vm/cancel_tasks/", object); } // TODO: task_list }