本文整理汇总了C#中CloudServersProvider.CreateImage方法的典型用法代码示例。如果您正苦于以下问题:C# CloudServersProvider.CreateImage方法的具体用法?C# CloudServersProvider.CreateImage怎么用?C# CloudServersProvider.CreateImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CloudServersProvider
的用法示例。
在下文中一共展示了CloudServersProvider.CreateImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Should_Create_Image_From_Server
public void Should_Create_Image_From_Server()
{
var provider = new CloudServersProvider(_testIdentity);
var detail = provider.GetDetails(_testServer.Id);
_testImageName = "Image_of_" + detail.Id;
var sucess = provider.CreateImage(detail.Id, _testImageName);
Assert.IsTrue(sucess);
}
示例3: 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)
{
//.........这里部分代码省略.........