本文整理汇总了C#中CloudServersProvider.ListServers方法的典型用法代码示例。如果您正苦于以下问题:C# CloudServersProvider.ListServers方法的具体用法?C# CloudServersProvider.ListServers怎么用?C# CloudServersProvider.ListServers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CloudServersProvider
的用法示例。
在下文中一共展示了CloudServersProvider.ListServers方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
if (args.Length < 2 || args.Length > 3)
{
Console.WriteLine("Usage: {0} username api_key [region (US|UK)]", Environment.CommandLine);
Environment.Exit(1);
}
RackspaceImpersonationIdentity auth = new RackspaceImpersonationIdentity();
auth.Username = args[0];
auth.APIKey = args[1];
if (args.Length == 3)
{
if (args[2] != "UK" && args[2] != "US")
{
Console.WriteLine("region must be either US or UK", Environment.CommandLine);
Environment.Exit(1);
}
switch (args[2])
{
case "UK": { auth.CloudInstance = CloudInstance.UK; }; break;
case "US": { auth.CloudInstance = CloudInstance.Default; }; break;
}
}
else
{
auth.CloudInstance = CloudInstance.Default;
}
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(auth);
}
catch (ResponseException ex2)
{
Console.WriteLine("Authentication failed with the following message: {0}", ex2.Message);
Environment.Exit(1);
}
var cloudServers = new CloudServersProvider(auth);
var servers = cloudServers.ListServers();
foreach (Server serv in servers)
{
var date = System.DateTime.Now;
var success = serv.CreateSnapshot(serv.Name + "_" + date.Year + "-" + date.Month + "-" + date.Day);
if (success)
{
Console.WriteLine("Image for server {0} has been created successfully.", serv.Name);
}
else
{
Console.WriteLine("Image for server {0} could not be created.", serv.Name);
}
}
}
示例2: Main
static void Main(string[] args)
{
var identity = new CloudIdentity
{
Username = Environment.GetEnvironmentVariable("OPENSTACKNET_USER"),
APIKey = Environment.GetEnvironmentVariable("OPENSTACKNET_APIKEY")
};
var authProvider = new CloudIdentityProvider(identity);
Console.WriteLine("--- Servers ---");
var serversProvider = new CloudServersProvider(identity);
var servers = serversProvider.ListServers();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Id\t\t\t\t\tName");
Console.ResetColor();
Console.WriteLine();
foreach (var server in servers)
{
Console.WriteLine("{0}\t{1}", server.Id, server.Name);
}
Console.WriteLine();
Console.WriteLine("--- CDN Services ---");
var cdnService = new ContentDeliveryNetworkService(authProvider, "DFW");
var cdns = cdnService.ListServices();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Id\t\t\t\t\tName");
Console.ResetColor();
Console.WriteLine();
foreach (var cdn in cdns)
{
Console.WriteLine("{0}\t{1}", cdn.Id, cdn.Name);
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
示例3: Main
static void Main(string[] args)
{
const string region = "RegionOne";
// Configure OpenStack.NET
OpenStackNet.Configure(options => options.DefaultTimeout=TimeSpan.FromSeconds(5));
// Authenticate
var identityUrl = new Uri("http://example.com");
var user = new CloudIdentityWithProject();
var identity = new OpenStackIdentityProvider(identityUrl, user);
identity.Authenticate();
// Use legacy and new providers
var legacyNetworking = new CloudNetworksProvider(null, identity);
legacyNetworking.ListNetworks();
var networks = new NetworkingService(identity, region);
networks.ListNetworks();
var legacyCompute = new CloudServersProvider(null, identity);
legacyCompute.ListServers();
var compute = new ComputeService(identity, region);
compute.ListServers();
}
示例4: Should_Get_A_List_Of_Servers_Which_Should_Include_The_Newly_Created_Server
public void Should_Get_A_List_Of_Servers_Which_Should_Include_The_Newly_Created_Server()
{
var provider = new CloudServersProvider(_testIdentity);
var servers = provider.ListServers();
Assert.IsNotNull(servers);
Assert.IsTrue(servers.Any());
Assert.IsNotNull(servers.FirstOrDefault(s => s.Id == _testServer.Id));
}
示例5: CleanupServers
public void CleanupServers()
{
var provider = new CloudServersProvider(_testIdentity);
var srvs = provider.ListServers();
foreach (var svr in srvs.Where(s => s.Name == "net-sdk-test-server"))
provider.DeleteServer(svr.Id);
var networkProvider = new CloudNetworksProvider(_testIdentity);
var networks = networkProvider.ListNetworks();
foreach (var network in networks.Where(n => n.Label == "net-sdk-test-network" || n.Label == "net-sdk-test-network-for-server"))
networkProvider.DeleteNetwork(network.Id);
}
示例6: Main
public static void Main(string[] args)
{
// step-1
var username = "your_auth_username";
var password = "your_auth_password";
var project_name = "your_project_name";
var project_id = "your_project_id";
var auth_url = "http://controller:5000/v2.0";
var region = "your_region_name";
var networkid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
var identity = new CloudIdentityWithProject () {
Username = username,
Password = password,
ProjectId = new ProjectId(project_id),
ProjectName = project_name
};
var identityProvider = new OpenStackIdentityProvider (
new Uri (auth_url));
var conn = new CloudServersProvider (identity, identityProvider);
// step-2
var images = conn.ListImages (region: region);
foreach (var image in images) {
Console.WriteLine (string.Format(
"Image Id: {0} - Image Name: {1}",
image.Id,
image.Name));
}
// step-3
var flavors = conn.ListFlavors (region: region);
foreach (var flavor in flavors) {
Console.WriteLine (string.Format(
"Flavor Id: {0} - Flavor Name: {1}",
flavor.Id,
flavor.Name));
}
// step-4
var image_id = "97f55846-6ea5-4e9d-b437-bda97586bd0c";
var _image = conn.GetImage(image_id, region:region);
Console.WriteLine (string.Format(
"Image Id: {0} - Image Name: {1}",
_image.Id,
_image.Name));
// step-5
var flavor_id = "42";
var _flavor = conn.GetFlavor (flavor_id, region: region);
Console.WriteLine (string.Format(
"Flavor Id: {0} - Flavor Name: {1}",
_flavor.Id,
_flavor.Name));
// step-6
var instance_name = "testing";
var testing_instance = conn.CreateServer (instance_name,
_image.Id,
_flavor.Id,
region: region,
networks: new List<String> () { networkid });
Console.WriteLine (string.Format(
"Instance Id: {0} at {1}",
testing_instance.Id,
testing_instance.Links
));
// step-7
var instances = conn.ListServers(region:region);
foreach (var instance in instances) {
Console.WriteLine (string.Format(
"Instance Id: {0} at {1}",
testing_instance.Id,
testing_instance.Links));
}
// step-8
conn.DeleteServer(testing_instance.Id, region:region);
// step-9
// step-10
// step-11
// step-12
// step-13
// step-14
// step-15
Console.Read ();
}
示例7: Main
static void Main(string[] args)
{
/* Login
* List servers
* select server to clone
* create image of server
* create server using image
* delete image
*/
Console.WriteLine();
if (ParseArguments(args))
{
Console.WriteLine("Logging in...");
if (Login())
{
var cloudServers = new CloudServersProvider(auth);
Console.WriteLine("Listing servers...");
try
{
var servers = cloudServers.ListServers(status: ServerState.ACTIVE, limit: 9, region: ServerRegion).ToList();
if (servers.Count == 0)
throw new Exception("No active servers on account");
Console.WriteLine();
for (int i = 0; i < servers.Count(); i++)
{
Console.WriteLine(String.Format("{0,2} {1}", i+1, servers[i].Name));
}
Console.WriteLine();
var validSelection = false;
int index = -1;
do
{
Console.Write(String.Format("Select server to clone [1-{0}]:", Math.Min(9, servers.Count)));
var selection = Console.ReadLine();
if (Int32.TryParse(selection, out index))
{
index--;
validSelection = (index >= 0 && index < servers.Count);
}
} while (!validSelection);
var imageName = String.Format("clone{0}", DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"));
Console.Write("Enter new server name:");
var serverName = Console.ReadLine();
// get detailed information of the selected server, this allows us to access the server's flavor ID
var server = cloudServers.GetDetails(servers[index].Id, ServerRegion);
Console.WriteLine("Creating image...");
if (cloudServers.CreateImage(servers[index].Id, imageName, region: ServerRegion))
{
SimpleServerImage image = null;
// find the image we just created so we can monitor the progress.
image = cloudServers.ListImages(server: servers[index].Id, region: ServerRegion).Where(result => result.Name == imageName).Single();
if (image != null)
{
try
{
image.WaitForActive(progressUpdatedCallback: delegate(int p)
{
Console.SetCursorPosition(0, Console.CursorTop - 1);
Console.WriteLine(String.Format("{0} {1}%", "Creating image...", p));
});
Console.WriteLine("Creating Server...");
var newServer = cloudServers.CreateServer(serverName, image.Id, server.Flavor.Id, region: ServerRegion);
Console.WriteLine(String.Format(" {0,-2} {1,-10} {2,-14} {3,-15} {4,-10} {5,-21}", "%", "Name", "Password", "IPv4", "Status", "Task"));
Console.WriteLine();
newServer.WaitForActive(progressUpdatedCallback: delegate(int p)
{
server = newServer.GetDetails();
Console.SetCursorPosition(0, Console.CursorTop - 1);
Console.WriteLine(String.Format("{0,-3} {1,-10} {2,-14} {3,-15} {4,-10} {5,-21}", p, server.Name, newServer.AdminPassword, server.AccessIPv4, server.VMState, server.TaskState));
});
// output the server details one last time so we capture the IPv4 address.
server = newServer.GetDetails();
Console.SetCursorPosition(0, Console.CursorTop - 1);
Console.WriteLine(String.Format("100 {0,-10} {1,-14} {2,-15} {3,-10} {4,-21}", server.Name, newServer.AdminPassword, server.AccessIPv4, server.VMState, server.TaskState));
}
finally
{
Console.WriteLine("Cleaning up temporary image...");
Console.WriteLine();
if (image.Delete())
{
image.WaitForDelete(progressUpdatedCallback: delegate(int p)
{
//.........这里部分代码省略.........