-
Notifications
You must be signed in to change notification settings - Fork 98
Rackspace Cloud Networks Code Samples
Sample code for working with the CloudNetworksProvider
CloudNetworksProvider requires a CloudIdentity instance for all operations, which can be created using Username/Password or Username/APIKey.
var cloudIdentity = new CloudIdentity() { Username = "username", Password = "password" };or
var cloudIdentity = new CloudIdentity() { APIKey = "apikey", Username = "username" };For more information on IdentityProvider
There are 2 ways to pass in the identity credentials to CloudNetworksProvider:
-
In the constructor
-
An optional parameter of each method
Our samples below will assume the identity has been passed into the constructor.
var networksProvider = new CloudNetworksProvider(cloudIdentity);
var cidr = "172.16.0.0/24";
var newNetwork = networksProvider.CreateNetwork(cidr, "your-network-name");This will return a CloudNetwork object with values for the newly created network that includes the unique Id of the network
var networksProvider = new CloudNetworksProvider(cloudIdentity);
var network = networksProvider.ShowNetwork("c1a01b77-2808-4c40-8869-ea7c0836170a");This returns a CloudNetwork object with the following properties:
Id- the system-generated UUID identifier for the network
Cidr- the CIDR supplied during network creation
Label- the label supplied during network creation
var networksProvider = new CloudServersProvider(cloudIdentity);
var networks = new List<Guid>() { new Guid("9823c221-bc4b-46a1-b79e-ba0736ba3a5d") }; //ID of the specified network
var testServer = provider.CreateServer("server-name", "image-identifier", "2", networks: networks);var networksProvider = new CloudServersProvider(cloudIdentity);
var networks = new List<Guid>() { new Guid("9823c221-bc4b-46a1-b79e-ba0736ba3a5d") }; //ID of the specified network
var testServer = provider.CreateServer("server-name", "image-identifier", "2", attachToPublicNetwork: true, attachToServiceNetwork:true, networks: networks);var networksProvider = new CloudNetworksProvider(cloudIdentity);
var network = networksProvider.DeleteNetwork("c1a01b77-2808-4c40-8869-ea7c0836170a");NOTE: If the network has any servers on it, this operation will fail and a UserAuthorizationException will be thrown.
If the network has already been deleted, an ItemNotFoundException will be thrown.
