1.0.2 • Published 6 years ago

@upcloud/upcloud v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

UpCloud JavaScript API client library

Build Status npm version License

This is a Javascript API client library that provides integration with the UpCloud API. It allows cloud resource management on UpCloud's IaaS with easy to use functions. The API client follows the RESTful web service principles wherever possible.

The base URL for all API operations is https://api.upcloud.com/ and require basic authentication using UpCloud username and password. We recommend creating a subaccount dedicated for the API communication for security purposes. This allows you to restrict API access by servers, storages, and tags ensuring you will never accidentally affect critical systems.

Table of content

Installation

For Node.js

npm

Install it via:

npm install @upcloud/upcloud --save
Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your upcloud from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('upcloud') in javascript files from the directory you ran the last command above from.

git

Install the library via git:

    npm install UpCloudLtd/upcloud-javascript-api --save

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file, that's to say your javascript file where you actually use this library):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Usage

Please follow the installation instruction and execute the following JS code (NOTE: In real production applications you should use for example ENV variables instead of inserting credentials directly to code and to version control):

var upcloud = require('upcloud');

var defaultClient = upcloud.ApiClient.instance;

// Configure HTTP basic authorization: baseAuth
var baseAuth = defaultClient.authentications['baseAuth'];
baseAuth.username = 'UPCLOUD_USERNAME'
baseAuth.password = 'UPCLOUD_PASSWORD'

var api = new upcloud.AccountApi()
api.getAccount().then(function(data) {
  console.log('API called successfully. Returned data: ' + data);
}, function(error) {
  console.error(error);
});

Documentation

All URIs are relative to https://api.upcloud.com/1.2

ClassMethodHTTP requestDescription
upcloud.AccountApigetAccountGET /accountAccount information
upcloud.FirewallApicreateFirewallRulePOST /server/{serverId}/firewall_ruleCreate firewall rule
upcloud.FirewallApideleteFirewallRuleDELETE /server/{serverId}/firewall_rule/{firewallRuleNumber}Remove firewall rule
upcloud.FirewallApigetFirewallRuleGET /server/{serverId}/firewall_rule/{firewallRuleNumber}Get firewall rule details
upcloud.FirewallApiserverServerIdFirewallRuleGetGET /server/{serverId}/firewall_ruleList firewall rules
upcloud.IPAddressApiaddIpPOST /ip_addressAssign IP address
upcloud.IPAddressApideleteIpDELETE /ip_address/{ip}Release IP address
upcloud.IPAddressApigetDetailsGET /ip_address/{ip}Get IP address details
upcloud.IPAddressApilistIpsGET /ip_addressList IP addresses
upcloud.IPAddressApimodifyIpPUT /ip_address/{ip}Modify IP address
upcloud.PlanApilistPlansGET /planList available plans
upcloud.PricesApilistPricesGET /priceList prices
upcloud.ServerApiassignTagPOST /server/{serverId}/tag/{tagList}Assign tag to a server
upcloud.ServerApiattachStoragePOST /server/{serverId}/storage/attachAttach storage
upcloud.ServerApicreateFirewallRulePOST /server/{serverId}/firewall_ruleCreate firewall rule
upcloud.ServerApicreateServerPOST /serverCreate server
upcloud.ServerApideleteFirewallRuleDELETE /server/{serverId}/firewall_rule/{firewallRuleNumber}Remove firewall rule
upcloud.ServerApideleteServerDELETE /server/{serverId}Delete server
upcloud.ServerApidetachStoragePOST /server/{serverId}/storage/detachDetach storage
upcloud.ServerApiejectCdromPOST /server/{serverId}/cdrom/ejectEject CD-ROM
upcloud.ServerApigetFirewallRuleGET /server/{serverId}/firewall_rule/{firewallRuleNumber}Get firewall rule details
upcloud.ServerApilistServerConfigurationsGET /server_sizeList server configurations
upcloud.ServerApilistServersGET /serverList of servers
upcloud.ServerApiloadCdromPOST /server/{serverId}/storage/cdrom/loadLoad CD-ROM
upcloud.ServerApimodifyServerPUT /server/{serverId}Modify server
upcloud.ServerApirestartServerPOST /server/{serverId}/restartRestart server
upcloud.ServerApiserverDetailsGET /server/{serverId}Get server details
upcloud.ServerApiserverServerIdFirewallRuleGetGET /server/{serverId}/firewall_ruleList firewall rules
upcloud.ServerApistartServerPOST /server/{serverId}/startStart server
upcloud.ServerApistopServerPOST /server/{serverId}/stopStop server
upcloud.ServerApiuntagPOST /server/{serverId}/untag/{tagName}Remove tag from server
upcloud.StorageApiattachStoragePOST /server/{serverId}/storage/attachAttach storage
upcloud.StorageApibackupStoragePOST /storage/{storageId}/backupCreate backup
upcloud.StorageApicancelOperationPOST /storage/{storageId}/cancelCancel storage operation
upcloud.StorageApicloneStoragePOST /storage/{storageId}/cloneClone storage
upcloud.StorageApicreateStoragePOST /storageCreate storage
upcloud.StorageApideleteStorageDELETE /storage/{storageId}Delete storage
upcloud.StorageApidetachStoragePOST /server/{serverId}/storage/detachDetach storage
upcloud.StorageApiejectCdromPOST /server/{serverId}/cdrom/ejectEject CD-ROM
upcloud.StorageApifavoriteStoragePOST /storage/{storageId}/favoriteAdd storage to favorites
upcloud.StorageApigetStorageDetailsGET /storage/{storageId}Get storage details
upcloud.StorageApilistStorageTypesGET /storage/{type}/List of storages by type
upcloud.StorageApilistStoragesGET /storageList of storages
upcloud.StorageApiloadCdromPOST /server/{serverId}/storage/cdrom/loadLoad CD-ROM
upcloud.StorageApimodifyStoragePUT /storage/{storageId}Modify storage
upcloud.StorageApirestoreStoragePOST /storage/{storageId}/restoreRestore backup
upcloud.StorageApitemplatizeStoragePOST /storage/{storageId}/templatizeTemplatize storage
upcloud.StorageApiunfavoriteStorageDELETE /storage/{storageId}/favoriteRemove storage from favorites
upcloud.TagApiassignTagPOST /server/{serverId}/tag/{tagList}Assign tag to a server
upcloud.TagApicreateTagPOST /tagCreate a new tag
upcloud.TagApideleteTagDELETE /tag/{tagName}Delete tag
upcloud.TagApilistTagsGET /tagList existing tags
upcloud.TagApimodifyTagPUT /tag/{tagName}Modify existing tag
upcloud.TagApiuntagPOST /server/{serverId}/untag/{tagName}Remove tag from server
upcloud.TimezoneApilistTimezonesGET /timezoneList timezones
upcloud.ZoneApilistZonesGET /zoneList available zones

Documentation of the models

Documentation for authorization

Take care if storing usernames or passwords in files while developing API applications to avoid accidentally publishing your account credentials.

baseAuth

  • Type: HTTP basic authentication
  • Username: Your UpCloud API username
  • Password: Your UpCloud API user's password

Issues

Found a bug, have a problem using the client, or anything else about the library you would want to mention? Open a new issue here to get in contact.

License

This project is distributed under the MIT License, see LICENSE.txt for more information.