CiscoTool_v1/netmiko_socket/test.js

236 lines
7.1 KiB
JavaScript

// import Proxmox from "proxmox"
// const proxmox = new Proxmox('root@pam', 'CanTho#2', 'ct.apactech.io');
// // proxmox.getClusterStatus(function(err, response){
// // if(err) throw err;
// // else{
// // data = JSON.parse(response);
// // console.log(data);
// // }
// // });
// proxmox.getQemu("pmct1",function(err, response){
// if(err) throw err;
// else{
// data = JSON.parse(response);
// console.log(response);
// }
// });
// proxmox.qemu.stop("pmct1", 1233, function(err, response){
// if(err) throw err;
// else{
// data = JSON.parse(response);
// console.log(data);
// }
// });
// const agent = new https.Agent({
// rejectUnauthorized: false,
// });
// const axios = require('axios');
// const url = 'https://ct.apactech.io:8006/api2/json/nodes/pmct1/qemu';
// const cookie = 'PVEAuthCookie=PVE:root@pam:64B50DFA::D4JpI/QL3AIpCQJda6qDf3yWnb7RQJ1o6dh/VBHBwIb3Q988ioq72qox9QvZgGh4p4+SyfqM1PjTxM1CaDxl/CCgh/xM8oid23m44dRwNW4kxZU6vJZ8eguPtCPg8XgMN3sBxFF5I2ossUab7iwmcoWOznArTHHAO9Uetl5k+yjHn+g1QELFZgod0bbs3+RfbhdFtLfakxm0iuVYsCtOIDr6dVlwWyT7fho9SbuMKj85uiM6vgeVEoEYXMXJe64v5sCCVkvXGJ9eNkTvmb7SaBMh9V+6KQXPIVy0Y6ZbqZ8jnyJanuK9PmHceYIbyoA6m6R49wHldSFNKOw4B0EEdg==';
// axios
// .get(url, {
// headers: {
// Cookie: cookie,
// },
// httpsAgent: new https.Agent({
// rejectUnauthorized: false,
// }),
// })
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error(error);
// });
// let CSRF = ""
// let cookie1 ="PVEAuthCookie=PVE:root@pam:64B5116D::UhhOepj0PoT0L65yX3p6eqbNt+KhoP3P6AO7YIHTCHNDTNM9zORC1CebaUoMbYUySe3kAg26anwP6ZGEgeDbhMIxaN3SLZln8b78JAQRRDcRPxMJlVZJRzNV7g6muXd8AkOwlpA4VWWvVFWHNT8ODOCTr4b2y7gbp+feMi52RKTvJPo3qvYJiCzFCflOtxZqOEDiD75nS0LBQHIMTVNg2e0HCMB8CFBhIPYHt0BBS5pgVkpt6LnyiGb7efjnnuayu4wbRmR2w4lzSXWLB7JdiLF6QTauf1KnqoMwYeoWVLGAudkTWW9iFMmLseFTEWVH2/jB7TgTzwPXpht219eyrg=="
// console.log(cookie)
// const baseUrl = 'https://ct.apactech.io:8006/api2'; // Replace with your Proxmox server URL
// const username = 'root@pam'; // Replace with your Proxmox username
// const password = 'CanTho#2'; // Replace with your Proxmox password
// const node = 'pmct1'; // Replace with the target Proxmox node
// const vmName = 'new-vm'; // Replace with the desired name for the new VM
// const vmId = 200; // Replace with the desired ID for the new VM
// const isoPath = '/path/to/iso/image.iso'; // Replace with the local path to the ISO image file
// // Make a request to authenticate and obtain a CSRF token
// const res = axios.post("https://ct.apactech.io:8006/api2/json/access/ticket", {
// username: username,
// password: password
// })
// console.log(res)
// import axios from "axios";
// import https from "https";
// const getToken = async () => {
// const username = "root@pam";
// const password = "CanTho#2";
// let cookie = "PVEAuthCookie=";
// let CSRF = "";
// await axios
// .post(
// "https://ct.apactech.io:8006/api2/json/access/ticket",
// {
// username: username,
// password: password,
// },
// {
// httpsAgent: new https.Agent({
// rejectUnauthorized: false,
// }),
// }
// )
// .then((response) => {
// cookie += response.data.data.ticket;
// CSRF += response.data.data.CSRFPreventionToken;
// })
// .catch((error) => {
// console.error(error);
// });
// return {cookie: cookie, CSRF: CSRF}
// };
//Get list VM
// const getListVM = async ()=>{
// const {cookie, CSRF} = await getToken();
// const res = await axios
// .get("https://ct.apactech.io:8006/api2/json/nodes/pmct1/qemu", {
// headers: {
// Authorization: cookie,
// CSRFPreventionToken: CSRF,
// },
// httpsAgent: new https.Agent({
// rejectUnauthorized: false,
// }),
// })
// .catch((error) => {
// console.error(error);
// });
// return res.data
// }
// getListVM()
//Start VM
// await axios
// .post(
// "https://ct.apactech.io:8006/api2/json/nodes/pmct1/qemu/1233/status/start",
// null,
// {
// headers: {
// Authorization: cookie,
// CSRFPreventionToken: CSRF,
// },
// httpsAgent: new https.Agent({
// rejectUnauthorized: false,
// }),
// }
// )
// .then((res) => {
// console.log(res.data);
// })
// .catch((error) => {
// console.error(error);
// });
// const vmConfig = {
// vmid: 1334,
// name: "vm-test-API",
// memory: 2048,
// onboot: 1,
// ostype: 'l26', // Set the OS type (l26 for Linux 2.6 kernel)
// sockets: 1,
// cores: 1,
// ide2:"local:iso/ubuntu-22.04.1-live-server-amd64.iso,media=cdrom",
// scsihw: 'virtio-scsi-pci',
// scsi0: 'local:10,format=qcow2', // Disk size and format
// virtio0: `${storagePool}:${diskSizeGB},format=qcow2`, // Disk size and format
// ide2: `${storagePool}:${isoImage},media=cdrom`, // ISO image to attach as CD-ROM
// net0: `virtio,bridge=${networkBridge}`, // Network interface
// pool: 'local' // Replace with the storage pool name
// };
// const {cookie, CSRF} = await getToken();
// await axios
// .post(
// "https://ct.apactech.io:8006/api2/json/nodes/pmct1/qemu",
// vmConfig,
// {
// headers: {
// Authorization: cookie,
// CSRFPreventionToken: CSRF,
// },
// httpsAgent: new https.Agent({
// rejectUnauthorized: false,
// }),
// }
// )
// .then((res) => {
// console.log(res.data);
// })
// .catch((error) => {
// console.error(error);
// });
// const res = await axios
// .get("https://ct.apactech.io:8006/api2/json/nodes/pmct1/storage", {
// headers: {
// Authorization: cookie,
// CSRFPreventionToken: CSRF,
// },
// httpsAgent: new https.Agent({
// rejectUnauthorized: false,
// }),
// })
// .catch((error) => {
// console.error(error);
// });
// console.log(res.data)
import { exec, spawn } from "child_process"
// // Mảng lưu trữ các tiến trình con
// const childProcesses = [];
const a = exec(
"ps -eo pid,command |grep -E 'python3|index.js'", (error, stdout, stderr) => {
console.log('Output:', stdout);
console.error('Errors:', stderr);
}
);
// a.stdout.on("data", (data) => {
// console.log(data.toString())
// })
// // Hàm tạo tiến trình con bằng spawn và lưu trữ vào mảng
// const childProcess = exec('dir'); // Ví dụ: chạy lệnh 'ls -lh'
// // console.log(childProcess)
// const getSN = spawn(
// "python3",
// [
// "./getSN.py",
// "",
// "172.16.20.17",
// 23,
// "24",
// "7",
// 2024,
// ],
// { timeout: 150000 }
// );
// Liệt kê danh sách các tiến trình con sau 5 giây
// setInterval(()=>{
// console.log("process.children")
// },1000)