Giter VIP home page Giter VIP logo

cf-dotnet-sdk's Introduction

#Cloud Foundry .NET SDK The CloudFoundry .NET SDK allows you to easily access the the CloudController API from within your .NET Application

The full CF API Documentation is available at http://apidocs.cloudfoundry.org/

Getting Started

Target Frameworks

  • .NET Framework 4.5 Portable Class Library

Prerequisites

  • Visual Studio 2013 Update 2 or newer
  • Git client

Contribute

Build it locally

  • Clone the repo git clone https://github.com/hpcloud/cf-dotnet-sdk
  • Build the cf-dotnet-sdk.sln in Visual Studio 2013

Test your build

Unit tests

Run all tests inside the CloudFoundry.CloudController.V2.Client.Test project

Integration tests

If you have a working CloundFoundry environment you can run the integration tests within the CloudFoundry.CloudController.Test.Integration project.

Before running the integration tests, make sure you set you connection info in the app.config

How to contribute

We are looking forward to contributions from the community.

Feel free to open an pull request or create an issue.

Use the nuget package

Code Samples

Login

// use this only if your api is using an unsigned certificate
System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

CloudFoundryClient client = new CloudFoundryClient(new Uri("https://api.domain"), new System.Threading.CancellationToken());
AuthenticationContext refreshToken = null;
CloudCredentials credentials = new CloudCredentials();
credentials.User = "user";
credentials.Password = "password";
try
{
    refreshToken = client.Login(credentials).Result;
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

List Apps

PagedResponseCollection<ListAllAppsResponse> apps = client.Apps.ListAllApps().Result;
while (apps != null && apps.Properties.TotalResults != 0)
{
    foreach (var app in apps)
    {
        Console.WriteLine("Application {0}, guid {1}, state {2}", app.Name, app.EntityMetadata.Guid, app.State);
    }
    apps = apps.GetNextPage().Result;
}

Stop an App

Guid appGuid = new Guid("52b6b758-848b-4b8d-b3f2-83736b5fae68");            
UpdateAppRequest updateApp = new UpdateAppRequest();
updateApp.State = "STOPPED";
UpdateAppResponse response = client.Apps.UpdateApp(appGuid, updateApp).Result;
Console.WriteLine("App {0} state is {1}", response.Name, response.State);

Use the V3 client

using CloudFoundry.CloudController.V2;

Uri target = new Uri("https://api.domain");
Uri httpProxy = null;
Uri authEndpoint = new Uri("https://uaa.domain");
bool skipSsl = true;

CloudFoundryClient v3client = new CloudFoundryClient(target, new System.Threading.CancellationToken(), httpProxy, skipSsl, authEndpoint);
AuthenticationContext refreshToken = null;
CloudCredentials credentials = new CloudCredentials();
credentials.User = "user";
credentials.Password = "password";
try
{
    refreshToken = v3client.Login(credentials).Result;
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

PagedResponseCollection<ListAllAppsResponse> apps = v3client.Apps.ListAllApps().Result;
foreach (ListAllAppsResponse app in apps)
{
    Console.WriteLine(app.Name);
}

Load a cf manifest

using CloudFoundry.Manifests;

Manifest manifest = ManifestDiskRepository.ReadManifest(@"path\to\manifest");
var apps = manifest.Applications();
foreach(var app in apps)
{
    Console.WriteLine("Application {0}, Memory {1}, Instances {2}", app.Name, app.Memory, app.InstanceCount);
}

cf-dotnet-sdk's People

Contributors

carabasdaniel avatar florindragos avatar gertd avatar mihaibuzgau avatar stefanschneider avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.