Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #40 from cneira/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
cneira authored Apr 28, 2020
2 parents 2d396aa + c893de1 commit 13f0a4f
Show file tree
Hide file tree
Showing 5 changed files with 1,222 additions and 791 deletions.
71 changes: 67 additions & 4 deletions lib/imgadm.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ function filter_images(err, resp, data) {
if (vms.error)
console.log(vms.error);

var filtered = vms.filter(function(e) {
return e.type == 'lx-dataset';
});
var ds = [];
filtered.forEach(function(e) {
vms.forEach(function(e) {
ds.push({
UUID: e.uuid,
NAME: e.name,
Expand Down Expand Up @@ -346,6 +343,7 @@ function Isactivated(out) {
'pkg install system/zones/brand/bhyve\n' +
'pkg install brand/pkgsrc\n' +
'pkg install brand/kvm\n' +
'pkg install brand/illumos\n' +
'pkg install brand/kvm-driver\n' +
'pkg install brand/sparse');
return null;
Expand Down Expand Up @@ -899,6 +897,70 @@ function create_image(query, callback) {
}
}

function can_create_vm() {
try {
fs.writeFileSync(ZCAGE.VMS + '/.test');
fs.unlinkSync(ZCAGE.VMS + '/.test');
} catch (e) {
return false;
}
return true;
}


/* This will return the container configuration
* data, callback will receive the configuration object.
* library is the library of the image for example : library/ubuntu or
* gitea/gitea and tag the release of the container for example : latest
*/

function docker_get_config(library, tag, zname, cb) {
token = undefined;
request('https://auth.docker.io/token?service=registry.docker.io&scope=repository:' + library + ':pull&service=registry.docker.io', {
json: true
}, (err, res, body) => {
if (err) {
return console.log(err);
}
token = body.token;
request('https://registry-1.docker.io/v2/' + library + '/manifests/' + tag, {
json: true,
headers: {
'Authorization': 'Bearer ' + token,
'Accept': 'application/vnd.docker.distribution.manifest.v2+json'
}
}, (err, res, body) => {
if (err) {
return console.log(err);
}
if (Object.prototype.hasOwnProperty.call(body, "config")) {
digest = body.config.digest;
request('https://registry-1.docker.io/v2/' + library + '/blobs/' + digest, {
json: true,
headers: {
'Authorization': 'Bearer ' + token,
'Accept': 'application/vnd.docker.distribution.manifest.v2+json'
}
}, (err, res, body) => {
if (err) {
return console.log(err);
}
container_config = body.container_config;
conf = container_config;
cb(err, conf);
});
} else {
conf = body.history[0].v1Compatibility;
obj = JSON.parse(conf);
cb(err, obj.container_config, zname);
}
});
});

};


module.exports.docker_get_config = docker_get_config;
module.exports.list_images = list_images;
module.exports.list_avail = list_avail;
module.exports.getzss = getzss;
Expand All @@ -914,3 +976,4 @@ module.exports.fetch_by_provider = fetch_by_provider;
module.exports.container_images = container_images;
module.exports.image_id2fname = image_id2fname;
module.exports.create_image = create_image;
module.exports.can_create_vm = can_create_vm;
Loading

0 comments on commit 13f0a4f

Please sign in to comment.