本文整理汇总了C#中CloudServersProvider.GetImage方法的典型用法代码示例。如果您正苦于以下问题:C# CloudServersProvider.GetImage方法的具体用法?C# CloudServersProvider.GetImage怎么用?C# CloudServersProvider.GetImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CloudServersProvider
的用法示例。
在下文中一共展示了CloudServersProvider.GetImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateServerNodeAsync
private async Task<CloudServersServerNode> CreateServerNodeAsync(CloudServersProvider provider, Server server, FlavorDetails[] flavors, ServerImage[] images)
{
FlavorDetails flavor = flavors.FirstOrDefault(i => server.Flavor != null && string.Equals(server.Flavor.Id, i.Id, StringComparison.OrdinalIgnoreCase));
try
{
if (flavor == null && server.Flavor != null)
flavor = await Task.Run(() => provider.GetFlavor(server.Flavor.Id));
}
catch (ResponseException)
{
// ignore
flavor = null;
}
ServerImage image = images.FirstOrDefault(i => server.Image != null && string.Equals(server.Image.Id, i.Id, StringComparison.OrdinalIgnoreCase));
try
{
if (image == null && server.Image != null)
image = await Task.Run(() => provider.GetImage(server.Image.Id));
}
catch (ResponseException)
{
// ignore
image = null;
}
return new CloudServersServerNode(provider, server, flavor, image);
}
示例2: TestGetImage
public void TestGetImage()
{
IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
IEnumerable<ServerImage> images = ListAllImagesWithDetails(provider);
Assert.IsNotNull(images);
if (!images.Any())
Assert.Inconclusive("The test could not proceed because the specified account and/or region does not appear to contain any images.");
foreach (ServerImage image in images)
{
Assert.IsNotNull(image);
ServerImage details = provider.GetImage(image.Id);
Assert.AreEqual(image.Created, details.Created);
Assert.AreEqual(image.DiskConfig, details.DiskConfig);
Assert.AreEqual(image.Id, details.Id);
Assert.IsNotNull(details.Links);
Assert.AreEqual(image.Links.Length, details.Links.Length);
for (int i = 0; i < image.Links.Length; i++)
{
// this could start to fail if the server reorders links; if that occurs the test should be rewritten to allow it
Assert.AreEqual(image.Links[i].Href, details.Links[i].Href);
Assert.AreEqual(image.Links[i].Rel, details.Links[i].Rel);
}
Assert.AreEqual(image.MinDisk, details.MinDisk);
Assert.AreEqual(image.MinRAM, details.MinRAM);
Assert.AreEqual(image.Name, details.Name);
Assert.IsTrue(details.Progress >= 0 && details.Progress <= 100);
if (image.Server != null)
{
Assert.IsNotNull(details.Server);
Assert.AreEqual(image.Server.Id, details.Server.Id);
}
Assert.IsNotNull(details.Status);
Assert.AreEqual(image.Updated, details.Updated);
}
}
示例3: 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 ();
}