copyright | lastupdated | ||
---|---|---|---|
|
2018-06-01 |
{:shortdesc: .shortdesc} {:new_window: target="_blank"} {:codeblock: .codeblock} {:pre: .pre} {:screen: .screen} {:tip: .tip} {:download: .download}
IBM Virtual Private Cloud (VPC) functionality is available through the IBM Console {: new_window}, IBM Cloud CLI, and REST API. For the Beta release, accounts must be granted access before the functionality is available. See Getting Started for the steps of how to be added.
To manage VPC resources and instantiate Virtual Server Instances (VSIs), review each user's permissions.
To use the IBM Console UI, go to https://console.bluemix.net/is {: new_window}. You can follow the steps in our UI guide for more information.
To use the CLI and API, follow the steps below.
- Install the IBM Cloud CLI
{: new_window}.
- Generate a public SSH key to provision Virtual Server Instances (VSIs).
You may have a public SSH key already. Look for a file called id_rsa.pub
under an .ssh
directory under your home directory, for example, /Users/<USERNAME>/.ssh/id_rsa.pub
. The file starts with ssh-rsa
and ends with your email address.
If you do not have a public SSH key or if you forgot the password of an existing one, generate a new one by running the ssh-keygen
command and following the prompts.
The VPC CLI actions use the extension is
.
ibmcloud plugin install riaas
ibmcloud login -sso
ibmcloud sl init
ibmcloud is help
ibmcloud is help vpc-create
ibmcloud is help server-create
ibmcloud is vpcs
ibmcloud is subnets
ibmcloud is servers
ibmcloud is servers --json
For more details on CLI capability, see:
Once your account has been granted access, you will receive an email with the API endpoint and credentials. Use this information to run the APIs. The following steps take you through a simple example using cURL, if you are ready to get more advanced, follow more advanced sample code.
ibmcloud login --sso -a https://api.bluemix.net
{: codeblock}
This command returns a URL and prompts for a passcode. Go to that URL in your browser and log in. If successful, you will get a one-time passcode. Copy this passcode and paste it as a response on the prompt. After the authentication steps, you'll be prompted to choose an account. Choose the account that was granted access to participate in the Beta. Respond to any remaining prompts to finish logging in.
iam_token=$(ibmcloud iam oauth-tokens | awk '/IAM/{ print $4; }')
{: codeblock}
This command calls the IBM Cloud CLI, parses out the IAM token, and stores it in a variable you can use in later commands. To view your IAM token, run the command echo $iam_token
.
Note that you must repeat the preceding step to refresh your IAM token every hour, because the token expires.
For rias_endpoint
and credentials
, use the information given to you during onboarding.
rias_endpoint="<RIAS_API_ENDPOINT>"
credentials="<BASIC_AUTH_CREDENTIALS>"
{: codeblock}
Run the previous command to store the values as variables in your session. To verify that these variables were saved, run echo $rias_endpoint
and make sure the response is not empty.
curl $rias_endpoint/v1/regions -u $credentials -H "X-Auth-Token: $iam_token"
{: codeblock}
The previous command returns the regions available for VPC, in JSON format. At least one object should return.
curl $rias_endpoint/v1/flavors -u $credentials -H "X-Auth-Token: $iam_token"
{: codeblock}
The previous command returns the flavors available for your VSIs, in JSON format. At least one object should return.
curl $rias_endpoint/v1/images -u $credentials -H "X-Auth-Token: $iam_token"
{: codeblock}
The previous command returns the images available for your VSIs, in JSON format. At least one object should return.
curl $rias_endpoint/v1/vpcs -u $credentials -H "X-Auth-Token: $iam_token"
{: codeblock}
The previous command returns the VPCs that have been created under your account (if any), in JSON format.
Success! You are ready to move on to more advanced APIs. Check out more sample code. To see the complete list of available APIs, see API Reference.