Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add working server create and destroy
- Loading branch information
Ross Kukulinski
committed
Jul 23, 2013
1 parent
9492bb0
commit e1d9c7e
Showing
7 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env node | ||
var program = require('commander'); | ||
var helpers = require('../helpers'); | ||
var table = require('cli-table'); | ||
var dateFormat = require('dateFormat'); | ||
|
||
/* | ||
NOT SUPPORTED YET BY NODE-CLOUD PACKAGE | ||
*/ | ||
console.log('Not implemented yet'); | ||
process.exit(0); | ||
|
||
program | ||
.option('-c, --config <path>', 'set config path [./cloud.json]') | ||
.option('-n, --name <name>', 'Name of the instance to create') | ||
.option('-s, --server <serverId>', 'ServerId to create image from') | ||
.parse(process.argv); | ||
|
||
var config = program.config; | ||
if (!config) { | ||
config = process.env.HOME+'/pkgcloud-cli.json'; | ||
} | ||
|
||
if (!program.name | ||
|| !program.server) { | ||
console.log('You must specify a name and serverId'); | ||
process.exit(1); | ||
} | ||
|
||
var options = { | ||
name: program.name, | ||
server: program.server | ||
}; | ||
|
||
|
||
helpers.init(config, function(err, cloud) { | ||
cloud.createImage(options, function(err) { | ||
if (err) { | ||
console.log(err); | ||
process.exit(1); | ||
} | ||
console.log('Image '+program.name+' created from server '+program.server); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env node | ||
var program = require('commander'); | ||
var helpers = require('../helpers'); | ||
var table = require('cli-table'); | ||
var dateFormat = require('dateFormat'); | ||
|
||
program | ||
.option('-c, --config <path>', 'set config path [./cloud.json]') | ||
.option('-n, --name <name>', 'Name of the instance to create') | ||
.option('-i, --image <imageId>', 'Image ID to use') | ||
.option('-f, --flavor <flavorId>', 'Flavor ID to use') | ||
.option('-r, --region <region>', 'Region instance will be created in') | ||
.parse(process.argv); | ||
|
||
var config = program.config; | ||
if (!config) { | ||
config = process.env.HOME+'/pkgcloud-cli.json'; | ||
} | ||
|
||
if (!program.name | ||
|| !program.image | ||
|| !program.flavor | ||
|| !program.region) { | ||
console.log('You must specify a name, image, flavor, and region'); | ||
process.exit(1); | ||
} | ||
|
||
var srv_options = { | ||
flavor: program.flavor, | ||
image: program.image, | ||
region: program.region | ||
}; | ||
|
||
|
||
helpers.init(config, function(err, cloud) { | ||
cloud.createServer(program.name, 'pkgcloud-cli', srv_options, function(err, inst) { | ||
if (err) { | ||
console.log(err); | ||
process.exit(1); | ||
} | ||
var tbl = new table(); | ||
|
||
tbl.push( | ||
{ 'id': inst.id }, | ||
{ 'name': inst.name }, | ||
{ 'region': inst.region}, | ||
{ 'adminPass': inst.adminPass } | ||
); | ||
|
||
console.log(tbl.toString()); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
var program = require('commander'); | ||
var helpers = require('../helpers'); | ||
var table = require('cli-table'); | ||
var dateFormat = require('dateFormat'); | ||
|
||
program | ||
.option('-c, --config <path>', 'set config path [./cloud.json]') | ||
.option('-s, --server <serverId>', 'ServerID to delete') | ||
.parse(process.argv); | ||
|
||
var config = program.config; | ||
if (!config) { | ||
config = process.env.HOME+'/pkgcloud-cli.json'; | ||
} | ||
|
||
if (!program.server) { | ||
console.log('You must specify a serverId to delete'); | ||
process.exit(1); | ||
} | ||
|
||
helpers.init(config, function(err, cloud) { | ||
cloud.destroyServer(program.server, function(err, response) { | ||
if (err) { | ||
console.log(err); | ||
process.exit(1); | ||
} | ||
if(response && response.ok) { | ||
console.log('Server: '+response.ok+' successfully deleted'); | ||
} | ||
else { | ||
console.log(response); | ||
} | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters