Skip to content

Commit

Permalink
version 0.3.3
Browse files Browse the repository at this point in the history
Reworked the vm configurator.
You can now create a new disk file while creating the vm
  • Loading branch information
LucaOonk committed Apr 19, 2021
1 parent 61663df commit 28a4bd4
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 70 deletions.
Binary file modified .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Launcher",
"request": "launch",
"mainClass": "com.lucaoonk.virsh_gui.Launcher",
"projectName": "virsh_gui"
},
{
"type": "java",
"name": "Launch ApplicationSettings",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.lucaoonk.virsh_gui</groupId>
<artifactId>virsh_gui</artifactId>
<packaging>jar</packaging>
<version>0.3.2</version>
<version>0.3.3</version>
<name>virsh_gui</name>
<url>http://maven.apache.org</url>

Expand Down
Binary file modified src/main/java/com/lucaoonk/virsh_gui/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void defineDomain(String domainLocation, String domainName, Contex
if(domainLocation.equals("")){

if(context.defaultSaveLocation.equals("")){
Runtime.getRuntime().exec("/usr/local/bin/virsh define "+System.getProperty("user.home")+"/vms/"+domainName+"/"+domainName+".xml");
Runtime.getRuntime().exec("/usr/local/bin/virsh define "+context.getDefaultSaveLocation()+domainName+"/"+domainName+".xml");


}else{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lucaoonk.virsh_gui.Backend.Controllers;

import java.io.File;
import java.io.IOException;
import java.util.List;

Expand Down Expand Up @@ -38,6 +39,51 @@ public void stopVM(VM vm){

}

public static String createVMDiskthread(String vmDomain, Context context, String size, String diskFileLocation)
{
final String vmDomain2 = vmDomain;
final Context context2 = context;
final String sizeString = size;
final String diskFileLocation2 = diskFileLocation;
final String defeninitivePath;
if(diskFileLocation2.equals("")){

defeninitivePath= context2.getDefaultSaveLocation()+vmDomain2+"/"+ vmDomain2+".qcow2";

}else{
defeninitivePath= diskFileLocation2+ vmDomain2+".qcow2";

}


File myFile = new File(defeninitivePath);
myFile.getParentFile().mkdirs();

// define what thread will do here
if(diskFileLocation2.equals("")){
try {

Process process = Runtime.getRuntime().exec("/usr/local/bin/qemu-img create -f qcow2 "+context2.getDefaultSaveLocation()+vmDomain2+"/"+ vmDomain2+".qcow2 +"+sizeString);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}else{
try {
Process process = Runtime.getRuntime().exec("/usr/local/bin/qemu-img create -f qcow2 "+diskFileLocation2+ vmDomain2+".qcow2 +"+sizeString);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

return defeninitivePath;

}

private static void startVMthread(VM vm, Context context)
{
final VM vmToStart = vm;
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/lucaoonk/virsh_gui/Backend/Objects/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class Context {
public MainContent mainContent;
public JFrame mainJFrame;
public String defaultSaveLocation;
private static final String versionString = "0.3.2";
private static final String versionString = "0.3.3";
public Boolean checkForUpdates;
private String applicationDefaultSaveLocation;


public Context(){
Expand All @@ -30,13 +31,14 @@ public Context(){

private void initDefaults(){
this.checkForUpdates = true;
this.defaultSaveLocation= "";
this.defaultSaveLocation=System.getProperty("user.home")+"/vms/";
this.applicationDefaultSaveLocation=System.getProperty("user.home")+"/vms/";

}

public void updateVMList(ArrayList<VM> vmList){
this.vmList= vmList;
defaultSaveLocation= "";
// defaultSaveLocation= "";
this.currentSelectedVM = vmList.get(0);
}

Expand Down Expand Up @@ -76,4 +78,17 @@ public void refresh() {
public static String getVersion(){
return versionString;
}

public String getDefaultSaveLocation() {

if(defaultSaveLocation.equals("")){

return applicationDefaultSaveLocation;

}else{

return defaultSaveLocation;
}

}
}
36 changes: 36 additions & 0 deletions src/main/java/com/lucaoonk/virsh_gui/Backend/Objects/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,41 @@ public ArrayList<String> getForwardedPorts(){
return this.portsForwarded;
}

public String vmDetailsTable(){
String vmDetails = "<html><table><tr><td><b>Property</b></td><td><b>Value</b></td></tr>";
vmDetails+= "<tr><td>UUID:</td><td>"+this.getUUID()+"</td></tr>";
vmDetails+= "<tr><td>vnc:</td><td>"+this.vncIP+":"+this.vncPort+"</td></tr>";
vmDetails+= "<tr><td>CPU's:</td><td>"+this.getcpus()+"</td></tr>";
double ramAmount = 0;
if(Integer.parseInt(this.getRam()) > 1024){
ramAmount = Integer.parseInt(this.getRam()) * 1.024E-6;
}else{
ramAmount = Integer.parseInt(this.getRam());
}
vmDetails+= "<tr><td>Ram in GB:</td><td>"+ramAmount+"</td></tr>";


String disksString = "";
int amountOfDisks = 0;
for (Device dev : this.getDevices()) {
if(dev.getClass().getName().equals("com.lucaoonk.virsh_gui.Backend.Objects.Disk")){
amountOfDisks+=1;
Disk disk = (Disk) dev;
disksString+= disk.device + ":"+"<br>"+"&nbsp;Location: "+ disk.source + "<br>&nbsp;Type: "+ disk.driver + "<br><br>";

}

}
vmDetails+= "<tr><td>Attached Disks ("+amountOfDisks+") :</td><td>"+disksString+"</td></tr>";

String forwardedPorts = "";
for (String port : this.getForwardedPorts()) {
forwardedPorts+= port + "<br>";
}
vmDetails+= "<tr><td>Forwarded Ports ("+this.getForwardedPorts().size()+")<br> Protocol::External Port:Internal Port :</td><td>"+forwardedPorts+"</td></tr>";

vmDetails+= "</table></html>";
return vmDetails;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static void createNewVMDomain(VMCreationObject vmCreationObject, String s

}else{

File myFile = new File(System.getProperty ("user.home")+"/vms/"+vmCreationObject.vmName+"/"+vmCreationObject.vmName+".xml");
File myFile = new File(context.getDefaultSaveLocation()+vmCreationObject.vmName+"/"+vmCreationObject.vmName+".xml");
myFile.getParentFile().mkdirs();

StreamResult file = new StreamResult(myFile);
Expand Down Expand Up @@ -300,7 +300,7 @@ private static Node devicesNode(Document doc, VMCreationObject vmCreationObject,

for (Device device : vmCreationObject.devices) {

if(device.getClass().getName().equals("Backend.Objects.Disk")){
if(device.getClass().getName().equals("com.lucaoonk.virsh_gui.Backend.Objects.Disk")){
Disk disk = (Disk) device;


Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/lucaoonk/virsh_gui/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.lucaoonk.virsh_gui.ui.MainFrame;

Expand All @@ -19,14 +17,6 @@ public void run() {

System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Virsh GUI");
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

w1.init();
try {
w1.showMainFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ protected Boolean doInBackground() {
try {
HttpResponse<JsonNode> response = Unirest.get(urlToCheck).asJson();
JsonNode responseBody = response.getBody();
System.out.println(responseBody);

if (response.isSuccess()) {

System.out.println(responseBody);

String latestVersion = responseBody.getObject().get("tag_name").toString();

System.out.println("Latest version: "+ latestVersion);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/lucaoonk/virsh_gui/ui/ScrollableVMList.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ public void actionPerformed(ActionEvent e) {
}

if(e.getSource().equals(this.addNewVMButton)){
VMConfigurator vmConfigurator = new VMConfigurator(context);
vmConfigurator.show();
// VMConfigurator vmConfigurator = new VMConfigurator(context);
// vmConfigurator.show();
VMConfiguratorTabbedPane configurator = new VMConfiguratorTabbedPane(context);
configurator.show();
}

if(e.getSource().equals(this.showVMInfoButton)){
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/lucaoonk/virsh_gui/ui/VMConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class VMConfigurator extends JDialog{
private String[] diskTargets = {"vda", "vdb", "vdc", "vdd", "vde", "vdf", "vdg", "vdh", "vdi"};
private String[] cdromTargets = {"sda", "sdb", "sdc", "sdd", "sde", "sdf", "sdg", "sdh", "sdi"};
private String[] archs = {"x86_64", "arm", "i386", "m68k", "ppc", "ppc64"};

private String htmlStart = "<html>";
private String htmlEnd = "</html>";
private String boldStart = "<b>";
private String boldlEnd = "</b>";
/**
*
*/
Expand All @@ -44,47 +47,47 @@ public void show(){

d.setLayout(new GridLayout(12,2));

d.add(new JLabel("VM location:"));
d.add(new JLabel(htmlStart+boldStart+"VM location"+boldlEnd+": <br>if empty it wil be placed in the set default folder: "+context.getDefaultSaveLocation()+htmlEnd));
final JTextField vmLocation = new JTextField();
d.add(vmLocation);

d.add(new JLabel("VM Name:"));
d.add(new JLabel(htmlStart+boldStart+"VM Name:"+boldlEnd+htmlEnd));
final JTextField vmName = new JTextField();
d.add(vmName);

d.add(new JLabel("VM Cpu's:"));
d.add(new JLabel(htmlStart+boldStart+"VM Cpu's:"+boldlEnd+htmlEnd));
final JTextField vmCpus = new JTextField();
d.add(vmCpus);

d.add(new JLabel("Ram in GB:"));
d.add(new JLabel(htmlStart+boldStart+"Ram in GB:"+boldlEnd+htmlEnd));
final JTextField vmRam = new JTextField();
d.add(vmRam);

final JComboBox<String> vmArch = new JComboBox<String>(archs);
d.add(new JLabel("VM arch:"));
d.add(new JLabel(htmlStart+boldStart+"VM arch:"+boldlEnd+htmlEnd));
d.add(vmArch);

final JComboBox<String> diskTarget = new JComboBox<String>(diskTargets);
d.add(new JLabel("Disk device target:"));
d.add(new JLabel(htmlStart+boldStart+"Disk device target:"+boldlEnd+htmlEnd));
d.add(diskTarget);

d.add(new JLabel("Disk file location:"));
d.add(new JLabel(htmlStart+boldStart+"Disk file location:"+boldlEnd+htmlEnd));
final JTextField diskFileLocation = new JTextField();
d.add(diskFileLocation);

final JComboBox<String> cdromTarget = new JComboBox<String>(cdromTargets);
d.add(new JLabel("CDrom device target:"));
d.add(new JLabel(htmlStart+boldStart+"CDrom device target:"+boldlEnd+htmlEnd));
d.add(cdromTarget);

d.add(new JLabel("CDrom file location:"));
d.add(new JLabel(htmlStart+boldStart+"CDrom file location:"+boldlEnd+htmlEnd));
final JTextField cdromFileLocation = new JTextField();
d.add(cdromFileLocation);

d.add(new JLabel("VM arguments:"));
d.add(new JLabel(htmlStart+boldStart+"VM arguments:"+boldlEnd+htmlEnd));
final JTextField vmArguments = new JTextField();
d.add(vmArguments);

d.add(new JLabel("Forwarded ports:"));
d.add(new JLabel(htmlStart+boldStart+"Forwarded ports"+boldlEnd+":<br> format: protocol::external Port-:interal Port<br>e.g.: tcp::2222:22,tcp::8080-8081:80"+htmlEnd));
final JTextField vmForwardedPorts = new JTextField();
d.add(vmForwardedPorts);

Expand Down
Loading

0 comments on commit 28a4bd4

Please sign in to comment.