C# client for UpCloud's API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.swagger-codegen
docs
src
.gitignore
.swagger-codegen-ignore
.travis.yml
LICENSE
README.md
Upcloud.sln
build.bat
build.sh
git_push.sh
mono_nunit_test.sh
nuget.exe

README.md

UpCloud C# API client library

Build Status

This C# API client for the UpCloud API provides a web service interface using HTTPS. It allows extensively featured 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

Frameworks supported

  • .NET 4.0 or later
  • Windows Phone 7.1 (Mango)

Dependencies

The DLLs included in the package may not be the latest version. We recommend using [NuGet] (https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:

Install-Package RestSharp
Install-Package Newtonsoft.Json

NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742

Installation

Run the following command to generate the DLL.

  • [Mac/Linux] /bin/sh build.sh
  • [Windows] build.bat

Then include the DLL (under the bin folder) in the C# project, and use the namespaces:

using Upcloud.Api;
using Upcloud.Client;
using Upcloud.Model;

Packaging

A .nuspec is included with the project. You can follow the Nuget quickstart to create and publish packages.

This .nuspec uses placeholders from the .csproj, so build the .csproj directly:

nuget pack -Build -OutputDirectory out Upcloud.csproj

Then, publish to a local feed or other host and consume the new package via Nuget as usual.

Usage

using System;
using System.Diagnostics;
using Upcloud.Api;
using Upcloud.Client;
using Upcloud.Model;

namespace Example
{
    public class Example
    {
        public void main()
        {

            // Configure HTTP basic authorization: baseAuth
            Configuration.Default.Username = Environment.GetEnvironmentVariable("UPCLOUD_USERNAME");
            Configuration.Default.Password = Environment.GetEnvironmentVariable("UPCLOUD_PASSWORD");

            var apiInstance = new AccountApi();

            try
            {
                // Account information
                AccountResponse result = apiInstance.GetAccount();
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling AccountApi.GetAccount: " + e.Message );
            }

        }
    }
}

Documentation

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

Class Method HTTP request Description
AccountApi GetAccount GET /account Account information
FirewallApi CreateFirewallRule POST /server/{serverId}/firewall_rule Create firewall rule
FirewallApi DeleteFirewallRule DELETE /server/{serverId}/firewall_rule/{firewallRuleNumber} Remove firewall rule
FirewallApi GetFirewallRule GET /server/{serverId}/firewall_rule/{firewallRuleNumber} Get firewall rule details
FirewallApi ServerServerIdFirewallRuleGet GET /server/{serverId}/firewall_rule List firewall rules
IPAddressApi AddIp POST /ip_address Assign IP address
IPAddressApi DeleteIp DELETE /ip_address/{ip} Release IP address
IPAddressApi GetDetails GET /ip_address/{ip} Get IP address details
IPAddressApi ListIps GET /ip_address List IP addresses
IPAddressApi ModifyIp PUT /ip_address/{ip} Modify IP address
PlanApi ListPlans GET /plan List available plans
PricesApi ListPrices GET /price List prices
ServerApi AssignTag POST /server/{serverId}/tag/{tagList} Assign tag to a server
ServerApi AttachStorage POST /server/{serverId}/storage/attach Attach storage
ServerApi CreateFirewallRule POST /server/{serverId}/firewall_rule Create firewall rule
ServerApi CreateServer POST /server Create server
ServerApi DeleteFirewallRule DELETE /server/{serverId}/firewall_rule/{firewallRuleNumber} Remove firewall rule
ServerApi DeleteServer DELETE /server/{serverId} Delete server
ServerApi DetachStorage POST /server/{serverId}/storage/detach Detach storage
ServerApi EjectCdrom POST /server/{serverId}/cdrom/eject Eject CD-ROM
ServerApi GetFirewallRule GET /server/{serverId}/firewall_rule/{firewallRuleNumber} Get firewall rule details
ServerApi ListServerConfigurations GET /server_size List server configurations
ServerApi ListServers GET /server List of servers
ServerApi LoadCdrom POST /server/{serverId}/storage/cdrom/load Load CD-ROM
ServerApi ModifyServer PUT /server/{serverId} Modify server
ServerApi RestartServer POST /server/{serverId}/restart Restart server
ServerApi ServerDetails GET /server/{serverId} Get server details
ServerApi ServerServerIdFirewallRuleGet GET /server/{serverId}/firewall_rule List firewall rules
ServerApi StartServer POST /server/{serverId}/start Start server
ServerApi StopServer POST /server/{serverId}/stop Stop server
ServerApi Untag POST /server/{serverId}/untag/{tagName} Remove tag from server
StorageApi AttachStorage POST /server/{serverId}/storage/attach Attach storage
StorageApi BackupStorage POST /storage/{storageId}/backup Create backup
StorageApi CancelOperation POST /storage/{storageId}/cancel Cancel storage operation
StorageApi CloneStorage POST /storage/{storageId}/clone Clone storage
StorageApi CreateStorage POST /storage Create storage
StorageApi DeleteStorage DELETE /storage/{storageId} Delete storage
StorageApi DetachStorage POST /server/{serverId}/storage/detach Detach storage
StorageApi EjectCdrom POST /server/{serverId}/cdrom/eject Eject CD-ROM
StorageApi FavoriteStorage POST /storage/{storageId}/favorite Add storage to favorites
StorageApi GetStorageDetails GET /storage/{storageId} Get storage details
StorageApi ListStorageTypes GET /storage/{type}/ List of storages by type
StorageApi ListStorages GET /storage List of storages
StorageApi LoadCdrom POST /server/{serverId}/storage/cdrom/load Load CD-ROM
StorageApi ModifyStorage PUT /storage/{storageId} Modify storage
StorageApi RestoreStorage POST /storage/{storageId}/restore Restore backup
StorageApi TemplatizeStorage POST /storage/{storageId}/templatize Templatize storage
StorageApi UnfavoriteStorage DELETE /storage/{storageId}/favorite Remove storage from favorites
TagApi AssignTag POST /server/{serverId}/tag/{tagList} Assign tag to a server
TagApi CreateTag POST /tag Create a new tag
TagApi DeleteTag DELETE /tag/{tagName} Delete tag
TagApi ListTags GET /tag List existing tags
TagApi ModifyTag PUT /tag/{tagName} Modify existing tag
TagApi Untag POST /server/{serverId}/untag/{tagName} Remove tag from server
TimezoneApi ListTimezones GET /timezone List timezones
ZoneApi ListZones GET /zone List available zones

Documentation of the models

Documentation for authorization

It's recommended to store the username and password as environmental variables 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.