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 1 commit
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
Prev Previous commit
Next Next commit
interface stats
  • Loading branch information
libvirtadept committed Dec 4, 2019
commit 026e41ccef464021c9726c003e3ed230a5f15d18
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/vmngr-development/dev_xml/node_modules/node-addon-api"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
42 changes: 42 additions & 0 deletions examples/interface_stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 });

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

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

const activeDomainNames = await Promise.all(activeDomains
.map((domain) => hypervisor.domainGetName(domain)));

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) {
process.stdout.write(chalk.green(` ${name}\n`));
}
process.stdout.write("\n");

process.stdout.write("Inactive Domains\n");
process.stdout.write("-----------------\n");
for (const name of inactiveDomainNames) {
process.stdout.write(chalk.red(` ${name}\n`));
}
process.stdout.write("\n");

})();
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
1 change: 1 addition & 0 deletions src/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Domain : public Napi::ObjectWrap<Domain> {
friend class DomainRebootWorker;
friend class DomainRestoreWorker;
friend class DomainGetXMLDescWorker;
friend class DomainInterfaceStatsWorker;
};

#endif // SRC_DOMAIN_H_
79 changes: 78 additions & 1 deletion src/hypervisor-domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This file is part of the vmngr/libvirt project and is subject to the MIT
* license as in the LICENSE file in the project root.
*/

#include "src/hypervisor.h"
#include "src/worker.h"
#include "src/domain.h"
Expand Down Expand Up @@ -812,3 +811,81 @@ Napi::Value Hypervisor::DomainGetXMLDesc(const Napi::CallbackInfo& info) {

return deferred.Promise();
}

/******************************************************************************
* DomainInterfaceStats *
******************************************************************************/
class DomainInterfaceStatsWorker : public Worker {
public:
DomainInterfaceStatsWorker(
Napi::Function const& callback,
Napi::Promise::Deferred deferred,
Hypervisor* hypervisor,
Domain* domain,
std::string device)
: Worker(callback, deferred, hypervisor),
domain(domain), device(device) {}

void Execute(void) override {
int ret = virDomainInterfaceStats(domain->domainPtr,
device.c_str(), &ifstats, size_t(0));
if (ret < 0) SetVirError();
}

void OnOK(void) override {
Napi::HandleScope scope(Env());

Napi::Object info = Napi::Object::New(Env());

info.Set("rx_bytes", Napi::Number::New(Env(), ifstats.rx_bytes));
info.Set("rx_packets", Napi::Number::New(Env(), ifstats.rx_packets));
info.Set("rx_errs", Napi::Number::New(Env(), ifstats.rx_errs));
info.Set("rx_drop", Napi::Number::New(Env(), ifstats.rx_drop));
info.Set("tx_bytes", Napi::Number::New(Env(), ifstats.tx_bytes));
info.Set("tx_packets", Napi::Number::New(Env(), ifstats.tx_packets));
info.Set("tx_errs", Napi::Number::New(Env(), ifstats.tx_errs));
info.Set("tx_drop", Napi::Number::New(Env(), ifstats.tx_drop));

deferred.Resolve(info);
Callback().Call({});
}

private:
Domain* domain;
std::string device;
virDomainInterfaceStatsStruct ifstats;
};

Napi::Value Hypervisor::DomainInterfaceStats(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

Napi::Function callback = Napi::Function::New(env, dummyCallback);
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env);

if (info.Length() <= 0 || !info[0].IsObject()) {
deferred.Reject(Napi::String::New(env, "Expected an object."));
return deferred.Promise();
}

if (info.Length() == 1) {
deferred.Reject(Napi::String::New(env, "Expected a domain ptr."));
return deferred.Promise();
} else if (info.Length() == 2 && !info[1].IsString()) {
deferred.Reject(Napi::String::New(env,
"Expected a interface device name at 2nd arg."));
return deferred.Promise();
}

Domain* domain = Napi::ObjectWrap<Domain>::Unwrap(
info[0].As<Napi::Object>());

std::string device = info[1].As<Napi::String>().Utf8Value();

DomainInterfaceStatsWorker* worker =
new DomainInterfaceStatsWorker(callback, deferred, this,
domain, device);
worker->Queue();

return deferred.Promise();
}
2 changes: 2 additions & 0 deletions src/hypervisor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Napi::Object Hypervisor::Init(Napi::Env env, Napi::Object exports) {
InstanceMethod("domainReboot", &Hypervisor::DomainReboot),
InstanceMethod("domainRestore", &Hypervisor::DomainRestore),
InstanceMethod("domainGetXMLDesc", &Hypervisor::DomainGetXMLDesc),
InstanceMethod("domainInterfaceStats",
&Hypervisor::DomainInterfaceStats),

InstanceMethod("nodeGetInfo", &Hypervisor::NodeGetInfo)
});
Expand Down
3 changes: 3 additions & 0 deletions src/hypervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DomainCreateWorker;
class DomainShutdownWorker;
class DomainRebootWorker;
class DomainGetXMLDescWorker;
class DomainInterfaceStatsWorker;

class NodeGetInfoWorker;

Expand Down Expand Up @@ -70,6 +71,7 @@ class Hypervisor : public Napi::ObjectWrap<Hypervisor> {
Napi::Value DomainReboot(const Napi::CallbackInfo& info);
Napi::Value DomainRestore(const Napi::CallbackInfo& info);
Napi::Value DomainGetXMLDesc(const Napi::CallbackInfo& info);
Napi::Value DomainInterfaceStats(const Napi::CallbackInfo& info);

Napi::Value NodeGetInfo(const Napi::CallbackInfo& info);

Expand Down Expand Up @@ -101,6 +103,7 @@ class Hypervisor : public Napi::ObjectWrap<Hypervisor> {
friend class DomainShutdownWorker;
friend class DomainRebootWorker;
friend class DomainGetXMLDescWorker;
friend class DomainInterfaceStatsWorker;

friend class NodeGetInfoWorker;
};
Expand Down