init
This commit is contained in:
12
src/main/java/cn/x47/service/VmService.java
Normal file
12
src/main/java/cn/x47/service/VmService.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package cn.x47.service;
|
||||
|
||||
|
||||
/**
|
||||
* hyper-v 虚拟操作相关接口
|
||||
*/
|
||||
public interface VmService {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
59
src/main/java/cn/x47/service/impl/VmServiceImpl.java
Normal file
59
src/main/java/cn/x47/service/impl/VmServiceImpl.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package cn.x47.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.x47.service.VmService;
|
||||
import com.github.tuupertunut.powershelllibjava.PowerShell;
|
||||
import com.github.tuupertunut.powershelllibjava.PowerShellExecutionException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class VmServiceImpl implements VmService {
|
||||
|
||||
public void test() {
|
||||
|
||||
|
||||
try (PowerShell psSession = PowerShell.open()) {
|
||||
String s = psSession.executeCommands("Get-VM");
|
||||
|
||||
// String s = psSession.executeCommands("Get-VMSwitch");
|
||||
String[] split = s.split("\\r\\n");
|
||||
List<String> allGroups = ReUtil.getAllGroups(Pattern.compile("(\\S+\\s+)"), split[1], false, true);
|
||||
List<Integer> integers = allGroups.stream().map(String::length).toList();
|
||||
|
||||
|
||||
List<List<String>> lists = Arrays.stream(split).skip(3).map(e -> {
|
||||
List<String> a = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
for (int i = 0; i < integers.size(); i++) {
|
||||
if (i == 0) {
|
||||
a.add(e.substring(index, integers.get(i)));
|
||||
|
||||
} else {
|
||||
a.add(e.substring(index, index + integers.get(i)));
|
||||
}
|
||||
|
||||
index += integers.get(i);
|
||||
}
|
||||
return a;
|
||||
}).toList();
|
||||
|
||||
|
||||
lists.forEach(System.out::println);
|
||||
|
||||
|
||||
} catch (IOException |
|
||||
PowerShellExecutionException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user