Skip to content
Branch: master
Find file History

readme.rst

Nutanix Developer Portal Code Samples - C#

To use the C# code samples, the following environment is recommended.

  • Visual Studio Community (free & recommended) or full Visual Studio (commercial software)
  • Access to a Nutanix Cluster for API testing purposes.
  • Nutanix Community Edition is supported but may not always provide the exact same APIs as a "full" Nutanix cluster.
  • The Newtonsoft.Json extension for .NET. To install Newtonsoft.Json, please see the official documentation. This will need to be done before continuing below.

Note

Please note that instructions provided in this repository will assume the use of Visual Studio Community software.

Console Applications

The provided C# console applications are designed to demonstrate use of the Nutanix Prism REST APIs from C#. To use the samples in your environment, please follow the instructions below.

The examples and screenshots below are from the list_vm_v3.cs sample.

  1. Open Visual Studio Community

  2. Select Create a new project

    new_project.png
  3. Select Console App (.NET Framework) from the list of options (it may be easier to search for console in the search bar)

    new_console_app.png
  4. Click Next and configure the app as appropriate for your environment (example shown below).

    configure_console_app.png
  5. Click Create

  6. Add a reference to NewtonSoft.Json:

    • Click View > Other Windows > Package Manager Console

    • Enter the following command:

      Install-Package Newtonsoft.Json -Version 12.0.2
  7. Add a reference to System.Web.Extensions - this is required for the System.Web.Script.Serialization that some code samples use:

    • Right-click References in the Solution Explorer and select Add Reference
    • Find System.Web.Extensions in the list and check the box next to it (the checkbox won't be visible until you mouse over the option)
    • Click OK
  8. When the new console application is created, the default Program.cs contents can be completely replaced (copied/pasted) with the code from the repository sample you are using.

    • Tip: Make sure you replace all the existing contents of Program.cs, including all Using statements at the top.
  9. In the default sample code, edit ClusterIp, ClusterUsername and ClusterPassword variables so they are correct for your environment.

  10. Either build (Ctrl-Shift-B) or run (F5) the application. The complete JSON response will be shown in the console application window.

  11. The screenshots below show two examples:

    • An example of a console app aimed at small environments with fewer than 500 VMs. This is taken from list_vm_v3.cs.
    • An example of a console app designed for larger environments i.e. more than 500 VMs. This is taken from list_vm_v3_large.cs.
    app_running.png
    app_running_large.png
You can’t perform that action at this time.