digitalocean
Version:
nodejs wrapper for digitalocean v2 api
203 lines (166 loc) • 7.61 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: digitalocean/floating_ip.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: digitalocean/floating_ip.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>(function() {
var slice = [].slice,
util = require('./util');
/**
* Floating IP resource
* @class FloatingIp
*/
var FloatingIp = (function() {
function FloatingIp(client) {
this.client = client;
}
/**
* List Floating IP objects.
*
* @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters
* @param {number} [perPage] - number of result per page to retrieve
* @param {listRequestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.list = function() {
var args = util.extractListArguments(arguments, 0);
return this.client.get.apply(this.client, ['/floating_ips', {}].concat(slice.call(args.params), [200, 'floating_ips', args.callback]));
};
/**
* Create a floating IP object.
*
* @param {object} attributes - The attributes with which to create the floating ip. See the {@link https://developers.digitalocean.com/documentation/v2/#floating-ips|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.create = function(attributes, callback) {
return this.client.post('/floating_ips', attributes, 202, 'floating_ip', callback);
};
/**
* Get the identified floating ip object.
*
* @param {string} ip - The IP of the floating ip to retrieve
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.get = function(ip, callback) {
var url = util.safeUrl('floating_ips', ip);
return this.client.get(url, {}, 200, 'floating_ip', callback);
};
/**
* Delete the identified floating ip object.
*
* @param {string} ip - The ip of the floating ip to delete
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.delete = function(ip, callback) {
var url = util.safeUrl('floating_ips', ip);
return this.client.delete(url, {}, 204, [], callback);
};
/**
* List of action objects.
*
* @param {string} ip - The IP of the floating ip for which to retrieve actions
* @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters
* @param {number} [perPage] - number of result per page to retrieve
* @param {listRequestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.listActions = function() {
var args = util.extractListArguments(arguments, 1);
var url = util.safeUrl('floating_ips', args.identifier, 'actions');
return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'actions', args.callback]));
};
/**
* Get the identified action object.
*
* @param {strint} ip - The IP of the floating ip for which to retrieve the action
* @param {number} id - The id of the action to retrieve
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.getAction = function(ip, id, callback) {
var url = util.safeUrl('floating_ips', ip, 'actions', id);
return this.client.get(url, {}, 200, 'action', callback);
};
/**
* Create an action on the identified floating ip.
*
* @param {strint} ip - The IP of the floating ip for which to create the action
* @param {string|object} parametersOrType - The name of the action to create or an object with key value pairs of parameters.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.action = function(ip, parametersOrType, callback) {
var parameters;
if(typeof parametersOrType === 'string') {
parameters = { type: parametersOrType };
} else {
parameters = parametersOrType;
}
var url = util.safeUrl('floating_ips', ip, 'actions');
return this.client.post(url, parameters, 201, 'action', callback);
};
/**
* If the identified floating IP is assigned to a Droplet, unassign it.
*
* @param {strint} ip - The IP of the floating ip for which to create the action
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.unassign = function(ip, callback) {
return this.action(ip, 'unassign', callback);
};
/**
* Assign the identified floating IP to a Droplet.
*
* @param {strint} ip - The IP of the floating ip for which to create the action
* @param {number|object} parametersOrDropletId - If a number, the identifier of the Droplet. Otherwise, an object with required keys of `droplet_id`. See the {@link https://developers.digitalocean.com/documentation/v2/#assign-a-floating-ip-to-a-droplet|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof FloatingIp
*/
FloatingIp.prototype.assign = function(ip, parametersOrDropletId, callback) {
var parameters;
if(typeof parametersOrDropletId !== 'object') {
parameters = {
droplet_id: parametersOrDropletId
};
} else {
parameters = parametersOrDropletId;
}
parameters.type = 'assign';
return this.action(ip, parameters, callback);
};
return FloatingIp;
})();
module.exports = FloatingIp;
}).call(this);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Account.html">Account</a></li><li><a href="Action.html">Action</a></li><li><a href="Certificate.html">Certificate</a></li><li><a href="Client.html">Client</a></li><li><a href="Domain.html">Domain</a></li><li><a href="Droplet.html">Droplet</a></li><li><a href="Firewall.html">Firewall</a></li><li><a href="FloatingIp.html">FloatingIp</a></li><li><a href="Image.html">Image</a></li><li><a href="ListResponse.html">ListResponse</a></li><li><a href="LoadBalancer.html">LoadBalancer</a></li><li><a href="Region.html">Region</a></li><li><a href="Size.html">Size</a></li><li><a href="Snapshot.html">Snapshot</a></li><li><a href="Tag.html">Tag</a></li><li><a href="Volume.html">Volume</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a>
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>