Comparing version 0.0.3 to 0.0.4
@@ -130,3 +130,3 @@ #!/usr/bin/env node | ||
return process.exit(0); | ||
return; | ||
} | ||
@@ -143,3 +143,3 @@ | ||
return process.exit(0); | ||
return; | ||
} | ||
@@ -163,3 +163,3 @@ | ||
if (opt.compact) { | ||
return process.exit(0); | ||
return; | ||
} | ||
@@ -169,3 +169,3 @@ | ||
if (body === null) return process.exit(0); | ||
if (body === null) return; | ||
@@ -256,2 +256,5 @@ switch (result.responseInfo.type) { | ||
!!body.status && table.push({ status : body.status }); | ||
!!body.availability&& table.push({ availability : body.availability }); | ||
!!body.migratedMB && table.push({ progress : Math.round(body.migratedMB / body.sizeMB * 100) + '%' }); | ||
!!body.sizeMB && table.push({ size : body.sizeMB + 'MB' }); | ||
!!body.macAddress && table.push({ 'mac address': body.macAddress }); | ||
@@ -342,3 +345,3 @@ !!body.ipAddress && table.push({ ipaddress : body.ipAddress }); | ||
return process.exit(0); | ||
return; | ||
}); |
@@ -26,2 +26,16 @@ var sacloud = require('../sacloud'); | ||
clone: { | ||
server : ['id:server', 'plan', 'id:product/server', 'name', 'p:name'] | ||
}, | ||
copy: { | ||
disk : ['id:disk', 'to', 'disk', 'id:disk'], | ||
archive : ['id:archive', 'to', 'disk', 'id:disk'] | ||
}, | ||
monitor: { | ||
server : ['id:server'], | ||
disk : ['id:disk'] | ||
}, | ||
show: { | ||
@@ -59,3 +73,4 @@ server : ['id:server'], | ||
status: { | ||
server : ['id:server'] | ||
server : ['id:server'], | ||
disk : ['id:disk'] | ||
}, | ||
@@ -62,0 +77,0 @@ |
@@ -159,6 +159,16 @@ /** | ||
} else { | ||
reqs.push({ | ||
method: 'get', | ||
path : [resource, args[0], 'power'].join('/') | ||
}); | ||
if (resource === 'server' || resource === 'appliance') { | ||
reqs.push({ | ||
method: 'get', | ||
path : [resource, args[0], 'power'].join('/') | ||
}); | ||
} else { | ||
reqs.push({ | ||
method: 'get', | ||
path : [resource, args[0]].join('/'), | ||
body : { | ||
Include: ['Availability', 'MigratedMB', 'SizeMB'] | ||
} | ||
}); | ||
} | ||
} | ||
@@ -266,2 +276,47 @@ | ||
break; | ||
case 'copy': | ||
if (args.length < 3 || args.length > 4) { | ||
throw new Error( | ||
'parameters is invalid' + '\n' + | ||
'usage: ' + sacloud.command.structure[action][resource].join(' ') | ||
); | ||
} | ||
if (args.length === 3) { | ||
reqs.push({ | ||
path : [resource, args[0]].join('/'), | ||
onRequested: function(err, res) { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
r.Name = res.response[res.responseInfo.key].name; | ||
r.Description = 'Copy of `' + res.response[res.responseInfo.key].name + '`'; | ||
r.Zone = { ID: res.response[res.responseInfo.key].storage.zone.id }; | ||
r.Plan = { ID: res.response[res.responseInfo.key].plan.id }; | ||
r.SizeMB = res.response[res.responseInfo.key].sizeMB; | ||
r.Connection = res.response[res.responseInfo.key].connection; | ||
} | ||
}); | ||
var body = {}; | ||
var r = {}; | ||
if (resource === 'disk') r.SourceDisk = { ID: args[0] }; | ||
if (resource === 'archive') r.SourceArchive = { ID: args[0] }; | ||
if (_.last(args) === 'disk') body.Disk = r; | ||
if (_.last(args) === 'archive') body.Archive = r; | ||
reqs.push({ | ||
method: 'POST', | ||
path : _.last(args), | ||
body : body | ||
}); | ||
} | ||
break; | ||
@@ -298,19 +353,22 @@ default: | ||
var reqs = []; | ||
//var reqs = []; | ||
this.reqs.forEach(function(req) { | ||
reqs.push(req); | ||
}); | ||
//this.reqs.forEach(function(req) { | ||
// reqs.push(req); | ||
//}); | ||
var count = 0; | ||
var total = this.reqs.length; | ||
var r = function _r() { | ||
if (reqs.length === 0) return; | ||
if (this.reqs.length === 0) return; | ||
var req = reqs.shift(); | ||
var req = this.reqs.shift(); | ||
this.opt.client.createRequest(req).send(function(err, result) { | ||
!!req.onRequested && req.onRequested(err, result, reqs[reqs.length] || null); | ||
!!req.onRequested && req.onRequested(err, result, count || null); | ||
callback(err, result, reqs.length + 1, this.reqs.length); | ||
callback(err, result, ++count, total); | ||
@@ -317,0 +375,0 @@ r(); |
{ | ||
"name": "sacloud", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A Node.js Module and CLI for SAKURA Internet Cloud APIs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
32066
957