本文整理汇总了C#中CloudServersProvider.ListImageMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# CloudServersProvider.ListImageMetadata方法的具体用法?C# CloudServersProvider.ListImageMetadata怎么用?C# CloudServersProvider.ListImageMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CloudServersProvider
的用法示例。
在下文中一共展示了CloudServersProvider.ListImageMetadata方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestListImageMetadata
public void TestListImageMetadata()
{
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.");
Console.WriteLine("Image metadata");
Console.WriteLine();
bool hadMetadata = false;
foreach (ServerImage image in images)
{
Assert.IsNotNull(image);
Metadata metadata = provider.ListImageMetadata(image.Id);
if (metadata.Count == 0)
continue;
hadMetadata = true;
Console.WriteLine("Image: {0}", image.Name);
foreach (KeyValuePair<string, string> pair in metadata)
Console.WriteLine(" {0}: {1}", pair.Key, pair.Value);
}
if (!hadMetadata)
Assert.Inconclusive("None of the images contained metadata.");
}
示例2: TestGetImageMetadataItem
public void TestGetImageMetadataItem()
{
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.");
int hadMetadata = 0;
int metadataCount = 0;
foreach (ServerImage image in images)
{
Assert.IsNotNull(image);
Metadata metadata = provider.ListImageMetadata(image.Id);
if (metadata.Count == 0)
continue;
hadMetadata++;
metadataCount += metadata.Count;
Console.WriteLine("Checking {0} metadata items for image '{1}'...", metadata.Count, image.Name);
foreach (KeyValuePair<string, string> pair in metadata)
Assert.AreEqual(pair.Value, provider.GetImageMetadataItem(image.Id, pair.Key));
if (hadMetadata >= 3 && metadataCount >= 30)
{
// this can be slow for a large number of images and metadata items,
// so stop after several are tested
break;
}
}
if (hadMetadata == 0)
Assert.Inconclusive("None of the images contained metadata.");
}
示例3: TestCreateImage
public void TestCreateImage()
{
IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
/* Create the image
*/
string imageName = UserComputeTests.UnitTestImagePrefix + Path.GetRandomFileName();
bool imaged = provider.CreateImage(_server.Id, imageName);
Assert.IsTrue(imaged);
ServerImage[] images = provider.ListImagesWithDetails(server: _server.Id, imageName: imageName).ToArray();
Assert.IsNotNull(images);
Assert.AreEqual(1, images.Length);
ServerImage image = images[0];
Assert.AreEqual(imageName, image.Name);
Assert.IsFalse(string.IsNullOrEmpty(image.Id));
Assert.AreEqual(ImageState.Active, provider.WaitForImageActive(image.Id).Status);
/* Test metadata operations on the image
*/
Assert.IsTrue(provider.SetImageMetadataItem(image.Id, "Item 1", "Value"));
Assert.AreEqual("Value", provider.GetImageMetadataItem(image.Id, "Item 1"));
Assert.IsTrue(provider.SetImageMetadataItem(image.Id, "Item 2", "Value ²"));
Assert.AreEqual("Value ²", provider.GetImageMetadataItem(image.Id, "Item 2"));
// setting the same key overwrites the previous value
Assert.IsTrue(provider.SetImageMetadataItem(image.Id, "Item 1", "Value 1"));
Assert.AreEqual("Value 1", provider.GetImageMetadataItem(image.Id, "Item 1"));
Assert.IsTrue(provider.DeleteImageMetadataItem(image.Id, "Item 1"));
Assert.IsFalse(provider.ListImageMetadata(image.Id).ContainsKey("Item 1"));
Metadata metadata = new Metadata()
{
{ "Different", "Variables" },
};
Assert.IsTrue(provider.UpdateImageMetadata(image.Id, metadata));
Metadata actual = provider.ListImageMetadata(image.Id);
Assert.IsNotNull(actual);
Assert.AreEqual(2, actual.Count);
Assert.AreEqual("Value ²", actual["Item 2"]);
Assert.AreEqual("Variables", actual["Different"]);
// a slight tweak
metadata["Different"] = "Values";
Assert.IsTrue(provider.SetImageMetadata(image.Id, metadata));
actual = provider.ListImageMetadata(image.Id);
Assert.IsNotNull(actual);
Assert.AreEqual(1, actual.Count);
Assert.AreEqual("Values", actual["Different"]);
Assert.IsTrue(provider.SetImageMetadata(image.Id, new Metadata()));
Assert.AreEqual(0, provider.ListImageMetadata(image.Id).Count);
/* Cleanup
*/
bool deleted = provider.DeleteImage(images[0].Id);
Assert.IsTrue(deleted);
provider.WaitForImageDeleted(images[0].Id);
}