Skip to content

features #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2f96b03
added reboot method
libvirtadept Nov 30, 2019
d53cedf
cpplint testing
libvirtadept Nov 30, 2019
c984c56
remove bad line ending
libvirtadept Nov 30, 2019
6c059dd
uri path change to default
libvirtadept Nov 30, 2019
f3444ae
fixes
libvirtadept Nov 30, 2019
f8a6695
up testing features
libvirtadept Dec 4, 2019
026e41c
interface stats
libvirtadept Dec 4, 2019
4602323
run tsc after install
libvirtadept Dec 4, 2019
9013dd5
test
libvirtadept Dec 4, 2019
d0c90f7
up
libvirtadept Dec 4, 2019
c3836fa
arg fix
libvirtadept Dec 4, 2019
931c5ae
arg fix
libvirtadept Dec 4, 2019
b1a42d8
type attempts fix
libvirtadept Dec 4, 2019
a2574a1
type attempts fix
libvirtadept Dec 4, 2019
f310717
type attempts fix
libvirtadept Dec 4, 2019
180707a
type attempts fix
libvirtadept Dec 4, 2019
2a57920
type attempts fix
libvirtadept Dec 4, 2019
b4ab28c
up
libvirtadept Dec 5, 2019
9b37823
added types for tune
libvirtadept Dec 5, 2019
3e4976e
type fix
libvirtadept Dec 5, 2019
0bb129c
typo fix
libvirtadept Dec 5, 2019
3265f8c
added tune current
libvirtadept Dec 6, 2019
7a73a48
added tune current bindings
libvirtadept Dec 6, 2019
b688c49
typo fix
libvirtadept Dec 6, 2019
450d888
linked glib-2.0 for g_malloc0_n | for iftunecurrent feature
libvirtadept Dec 6, 2019
bbff3a6
actually fixed
libvirtadept Dec 6, 2019
63d2312
removed noob's debug points xD
libvirtadept Dec 6, 2019
ee29ea7
added memory stats
Dec 9, 2019
6998610
up
Dec 9, 2019
6ab37da
added domain utils
Dec 9, 2019
2492a10
fix exports
Dec 9, 2019
25a58c1
i think it will right memory usage calc
Dec 9, 2019
0964b03
node memory stats
Dec 9, 2019
5dac600
push
Dec 9, 2019
1bf8f13
m
Dec 9, 2019
3170124
should be fixed
Dec 9, 2019
f99d2e6
return pretty
Dec 9, 2019
ad7a940
add types
Dec 9, 2019
7c2bfa1
up
Dec 9, 2019
a4c4954
units
Dec 9, 2019
28ac22c
usage fix attempts
Dec 9, 2019
31fa330
usage fix attempts
Dec 9, 2019
8fc855e
cpu usage. test implement
Dec 10, 2019
d6516ea
Merge branch 'master' into dev/xml
libvirtadept Jan 4, 2020
c049ab7
Update domain-builder.ts
libvirtadept Jan 6, 2020
29b72fc
Update domain-builder.ts
libvirtadept Jan 6, 2020
001f3dd
lock fix
libvirtadept Jan 6, 2020
3b0dd85
chai
libvirtadept Jan 6, 2020
a185266
temp attempt for docker
libvirtadept Jan 13, 2020
b76a653
add glib path
libvirtadept Jan 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/ilya/libvirt-dev/node_modules/node-addon-api"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [{
"type": "lldb",
"request": "launch",
"name": "Addon debug",
"program": "${workspaceFolder}/dist/examples/",
"preLaunchTask": "npm: build",
}]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files.exclude": {
"**/.git": false,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/node_modules": true,
"**/build": true,
"**/dist": true
}
}
7 changes: 5 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")",
"."
".",
"/usr/include/glib-2.0",
"/usr/lib/glib-2.0/include",
"/usr/lib/x86_64-linux-gnu/glib-2.0/include"
],
"link_settings": {
"libraries": [ "-lvirt" ]
"libraries": [ "-lvirt" , "-lglib-2.0" ]
}
}
]
Expand Down
97 changes: 97 additions & 0 deletions examples/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import chalk from "chalk";
import process from "process";

import libvirt, { Domain } from "../"
import { domainDescToXml, DomainDesc, DomainBuilder } from "../dist";
import uuidv1 from 'uuid/v1';

(async ()=>{
const uri = "qemu:///system";
const hypervisor = new libvirt.Hypervisor({ uri });

// Connecting to our hypervisor
await hypervisor.connectOpen();

const builDomainDesc = createDomainDesc("Example VM");

builDomainDesc.addDisk({
type: "file", device: "disk",
driver: { name: "qemu", type: "qcow2" },
source: { file: "/" }, // Define path of your qcow2 disk
target: { dev: "vda", bus: "virtio" }
});

const domainXML = domainDescToXml(builDomainDesc.build());

const domain: Domain = await hypervisor.domainDefineXML(domainXML);
// Our domain has been defined or edited if DomainDesc have existing uuid
// Then we can start domain

const domainName = await hypervisor.domainGetName(domain);

await hypervisor.domainCreate(domain).then(() => {
process.stdout.write(`Domain ${chalk.green(domainName)} started \n\n`)
}).catch((err) => {
process.stdout.write(`Error on starting ${chalk.red(domainName)} domain \n\n`);
})

await hypervisor.connectClose();

})()

function createDomainDesc(domainName: string){

const template: DomainDesc = {

type: "kvm",

memory: { value: 1048576 },
currentMemory: { value: 1048576 },

vcpu: { value: 1 },

os: {
type: { arch: "x86_64", machine: "q35", value: "hvm" },
boot: { dev: "hd" },
},

devices: [

{
type: "emulator",
emulator: { value: "/usr/bin/qemu-system-x86_64" },
},

{
type: "console",
console: { type: "pty" },
},

{
type: "graphics",
graphics: {
type: "vnc",
port: -1,
listen: "0.0.0.0",
passwd: "test1",
}
},

],

};

const domainUUID = uuidv1();
const domain = new DomainBuilder()
.fromTemplate(template)
.setName(domainName)
.setUUID(domainUUID)
.addInterface({
type: "network",
source: { network: "default" },
mac: { address: "52:54:00:8e:c6:5f" },
model: { type: "virtio" },
})

return domain;
}
29 changes: 29 additions & 0 deletions examples/interface_stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import chalk from "chalk";
import process from "process";
import util from 'util';

import libvirt from "../";

(async () => {
const vmName = "debian9-vm3", // VM name
ifName = "vnet2"; // VM Interface Name

const uri = "qemu+ssh://root@libvirt_dev/system";
const hypervisor = new libvirt.Hypervisor({ uri });

await hypervisor.connectOpen();

const hostname = await hypervisor.connectGetHostname();
process.stdout.write(`Connected to ${hostname}!\n\n`);

const activeDomain = await hypervisor.domainLookupByName(vmName).then(domain => domain).catch(() => null); // Domain not exist or error
if (!activeDomain){
console.log(`Error on lookup for ${chalk.blue(vmName)}`);
return;
}

const ifStats = await hypervisor.domainInterfaceStats(activeDomain, ifName);
console.log(`Domain ${chalk.green(vmName)} interface stats of ${chalk.green(ifName)} interface:`);

console.log(util.inspect(ifStats, { colors: true, sorted: true }));
})();
4 changes: 2 additions & 2 deletions examples/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import libvirt from "../";
const hypervisor = new libvirt.Hypervisor({ uri });

await hypervisor.connectOpen();

console.time('s');
const hostname = await hypervisor.connectGetHostname();
process.stdout.write(`Connected to ${hostname}!\n\n`);

Expand All @@ -24,7 +24,7 @@ import libvirt from "../";
const inactiveDomainNames = await Promise.all(inactiveDomains
.map((domain) => hypervisor.domainGetName(domain)));
await hypervisor.connectClose();

console.timeEnd('s')
process.stdout.write("Active Domains\n");
process.stdout.write("--------------\n");
for (const name of activeDomainNames) {
Expand Down
35 changes: 35 additions & 0 deletions examples/memorystats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import chalk from "chalk";
import process from "process";
import _ from "lodash";
import bytes from "bytes";
import { prettifyMemoryUsage } from '../dist/domain-utils'

import libvirt, { Domain } from "../";

(async () => {
const vmName = "debian9-vm1", // VM name
ifName = "vnet0"; // VM Interface Name

const uri = "qemu+ssh://root@libvirt_dev/system";
const hypervisor = new libvirt.Hypervisor({ uri });

await hypervisor.connectOpen();

const hostname = await hypervisor.connectGetHostname();
process.stdout.write(`Connected to ${hostname}!\n\n`);

const activeDomain = await hypervisor.domainLookupByName(vmName).then(domain => domain).catch(() => null); // Domain not exist or error
if (!activeDomain){
console.log(`Error on lookup for ${chalk.blue(vmName)}`);
return;
}

setInterval(async () => {
const memoryStats = await hypervisor.domainMemoryStats(activeDomain);
const pretty = prettifyMemoryUsage(memoryStats);
console.log(pretty);
// console.log(memoryStats);

// Pretty is just an example.
}, 1000)
})();
25 changes: 25 additions & 0 deletions examples/node_cpustats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import chalk from "chalk";
import process from "process";
import _ from "lodash";
import bytes from "bytes";

import libvirt, { Domain, prettifyCpuUsage } from "../";

(async () => {
const vmName = "debian9-vm1", // VM name
ifName = "vnet0"; // VM Interface Name

const uri = "qemu+ssh://root@libvirt_dev/system";
const hypervisor = new libvirt.Hypervisor({ uri });

await hypervisor.connectOpen();

const hostname = await hypervisor.connectGetHostname();
process.stdout.write(`Connected to ${hostname}!\n\n`);

const prev = await hypervisor.nodeCpuStats();
await new Promise(resolve => setTimeout(resolve, 1000));
const current = await hypervisor.nodeCpuStats();
const usage = prettifyCpuUsage(prev, current);
console.log(usage);
})();
19 changes: 19 additions & 0 deletions examples/node_memory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import chalk from "chalk";
import process from "process";
import util from 'util';

import libvirt from "../";

(async () => {
const vmName = "debian9-vm1", // VM name
ifName = "vnet0"; // VM Interface Name

const uri = "qemu+ssh://root@libvirt_dev/system";
const hypervisor = new libvirt.Hypervisor({ uri });

await hypervisor.connectOpen();

const hostname = await hypervisor.connectGetHostname();
process.stdout.write(`Connected to ${hostname}!\n\n`);
console.log(await hypervisor.nodeGetMemoryStats());
})();
53 changes: 53 additions & 0 deletions examples/parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import chalk from "chalk";
import process from "process";

import libvirt, { ConnectListAllDomainsFlags } from "../";

import { Parser, Builder } from 'xml2js'

(async () => {

const uri = "qemu+ssh://root@libvirt_dev/system";
const hypervisor = new libvirt.Hypervisor({ uri });

await hypervisor.connectOpen();

const hostname = await hypervisor.connectGetHostname();
process.stdout.write(`Connected to ${hostname}!\n\n`);

const debianDomain = await hypervisor.domainLookupByName('debian9-vm1');

const domainXML = await hypervisor.domainGetXMLDesc(debianDomain);

const xmlParser = new Parser({ headless: true, explicitRoot: false, rootName: 'domain'});
const xmlBuilder = new Builder({ headless: true, explicitRoot: false, rootName: "domain"});

const domainObj = await xmlParser.parseStringPromise(domainXML);

let domainVNCIndex = domainObj.devices[0].graphics.findIndex((graphics:any) => graphics.$.type === 'vnc');

const newVNCPort = parseInt(domainObj.devices[0].graphics[domainVNCIndex].$.port) + 1
domainObj.devices[0].graphics[domainVNCIndex].$.port = String(newVNCPort);


const domainChangeVNCXML = xmlBuilder.buildObject(domainObj);

await hypervisor.domainShutdown(debianDomain).then(()=>{
console.log("DOMAIN SHUTDOWN OK");
}).catch(err => {
console.log("shutdown err:", err);
});
await new Promise(resolve => setTimeout(resolve, 5000));

await hypervisor.domainDefineXML(domainChangeVNCXML).then(()=>{
console.log("DOMAIN DEFINE OK")
});

await hypervisor.domainCreate(debianDomain).then(()=>{
console.log("DOMAIN START OK");
console.log(`New VNC port : ${newVNCPort}`)
});

await hypervisor.connectClose();

})();
37 changes: 37 additions & 0 deletions examples/reboot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import chalk from "chalk";
import process from "process";

import libvirt from "../";

(async () => {

const uri = "qemu+ssh://root@libvirt_dev/system";
const hypervisor = new libvirt.Hypervisor({ uri });

// Connecting to our hypervisor
await hypervisor.connectOpen();

const activeDomains = await hypervisor.connectListAllDomains(
libvirt.ConnectListAllDomainsFlags.ACTIVE);

if (activeDomains.length === 0) {
process.stdout.write("No domains for reboot :( \n\n");
return;
}

for (const activeDomain of activeDomains) {
const domainName = await hypervisor.domainGetName(activeDomain);

process.stdout.write(`Rebooting domain: `
+ `${chalk.blue(domainName)} ... \n\n`);

await hypervisor.domainReboot(activeDomain).then(() => {
process.stdout.write(`domain ${chalk.green(domainName)} `
+ "is being to be rebooted!\n\n");
}).catch((err: Error) => {
process.stderr.write(`domain ${chalk.red(domainName)} reboot `
+ `ERROR: ${err}\n\n`);
});
}

})();
2 changes: 1 addition & 1 deletion examples/shutdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import libvirt from "../";
const domainName = await hypervisor.domainGetName(activeDomain);

process.stdout.write(`Shutting down domain: `
+ `${chalk.blue(domainName)} ... `);
+ `${chalk.blue(domainName)} ... \n\n`);

await hypervisor.domainShutdown(activeDomain).then(() => {
process.stdout.write(`domain ${chalk.green(domainName)} `
Expand Down
Loading