当前位置: 首页>>代码示例>>C#>>正文


C# CloudServersProvider.CreateServer方法代码示例

本文整理汇总了C#中CloudServersProvider.CreateServer方法的典型用法代码示例。如果您正苦于以下问题:C# CloudServersProvider.CreateServer方法的具体用法?C# CloudServersProvider.CreateServer怎么用?C# CloudServersProvider.CreateServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CloudServersProvider的用法示例。


在下文中一共展示了CloudServersProvider.CreateServer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClassInitialize

        public static void ClassInitialize(TestContext testContext)
        {
            IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
            string serverName = UserComputeTests.UnitTestServerPrefix + Path.GetRandomFileName();

            Flavor flavor = UserComputeTests.ListAllFlavorsWithDetails(provider).OrderBy(i => i.RAMInMB).ThenBy(i => i.DiskSizeInGB).FirstOrDefault();
            if (flavor == null)
                Assert.Inconclusive("Couldn't find a flavor to use for the test server.");

            SimpleServerImage[] images = UserComputeTests.ListAllImages(provider).ToArray();
            SimpleServerImage image = images.FirstOrDefault(i => i.Name.IndexOf("CentOS 6.0", StringComparison.OrdinalIgnoreCase) >= 0);
            if (image == null)
                Assert.Inconclusive("Couldn't find the CentOS 6.0 image to use for the test server.");

            Stopwatch timer = Stopwatch.StartNew();
            Console.Write("Creating server for image {0}...", image.Name);
            NewServer server = provider.CreateServer(serverName, image.Id, flavor.Id);
            Assert.IsNotNull(server);
            Assert.IsFalse(string.IsNullOrEmpty(server.Id));

            _password = server.AdminPassword;

            _server = provider.WaitForServerActive(server.Id);
            Assert.IsNotNull(_server);
            Assert.AreEqual(server.Id, _server.Id);
            Assert.AreEqual(ServerState.Active, _server.Status);

            Console.WriteLine("done. {0} seconds", timer.Elapsed.TotalSeconds);
        }
开发者ID:nick-o,项目名称:openstack.net,代码行数:29,代码来源:UserServerTests.cs

示例2: Should_Create_A_New_Server_In_DFW

        public void Should_Create_A_New_Server_In_DFW()
        {
            var provider = new CloudServersProvider(_testIdentity);
            _newTestServer = provider.CreateServer("net-sdk-test-server", _initImage.Id, _initFlavor.Id);

            Assert.IsNotNull(_newTestServer);
            Assert.IsNotNull(_newTestServer.Id);
        }
开发者ID:surgicalcoder,项目名称:openstack.net,代码行数:8,代码来源:CloudServersTests.cs

示例3: Should_Create_A_New_Complex_Server_In_DFW

        public void Should_Create_A_New_Complex_Server_In_DFW()
        {
            var provider = new CloudServersProvider(_testIdentity);
            _newTestServer2 = provider.CreateServer("net-sdk-test-server2", _initImage.Id, _initFlavor.Id, metadata: new Metadata { { "Key1", "Value1" }, { "Key2", "Value2" } }, attachToPublicNetwork: true, attachToServiceNetwork: true);

            Assert.IsNotNull(_newTestServer2);
            Assert.IsNotNull(_newTestServer2.Id);
        }
开发者ID:amitgandhinz,项目名称:openstack.net,代码行数:8,代码来源:CloudServersTests.cs

示例4: Should_Create_A_New_Complex_Server_In_DFW

        public void Should_Create_A_New_Complex_Server_In_DFW()
        {
            var provider = new CloudServersProvider(_testIdentity);
            _testServer2 = provider.CreateServer("net-sdk-test-server2", "d531a2dd-7ae9-4407-bb5a-e5ea03303d98", "2", metadata: new Metadata{{"Key1", "Value1"}, {"Key2", "Value2"}}, attachToPublicNetwork: true, attachToServiceNetwork: true);

            Assert.IsNotNull(_testServer2);
            Assert.IsNotNull(_testServer2.Id);
        }
开发者ID:Dan-Pallone-II,项目名称:openstack.net,代码行数:8,代码来源:CloudServersTests.cs

示例5: Should_Create_A_New_Server_In_DFW

        public void Should_Create_A_New_Server_In_DFW()
        {
            var provider = new CloudServersProvider(_testIdentity);
            _testServer = provider.CreateServer("net-sdk-test-server", "d531a2dd-7ae9-4407-bb5a-e5ea03303d98", "2");

            Assert.IsNotNull(_testServer);
            Assert.IsNotNull(_testServer.Id);
        }
开发者ID:Dan-Pallone-II,项目名称:openstack.net,代码行数:8,代码来源:CloudServersTests.cs

示例6: Run

    public async Task Run(string username, string apiKey, string region)
    {
        // Configure authentication
        var identity = new CloudIdentity
        {
            Username = username,
            APIKey = apiKey
        };
        var identityService = new CloudIdentityProvider(identity);
        var result = identityService.Authenticate();

        var serverService = new CloudServersProvider(identity, region, null, null);
        var rackConnectService = new RackConnectService(identityService, region);

        // Create a cloud server on your hybrid network
        Console.WriteLine($"Looking up your RackConnect network in {region}...");
        var networks = await rackConnectService.ListNetworksAsync();
        var network = networks.FirstOrDefault();
        if (network == null)
            throw new Exception($"You do not have a Hybrid Cloud / RackConnect network configured in the {region} which is required to run this sample.");

        Console.WriteLine("Creating sample cloud server... ");
        // Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
        const string ubuntuImageId = "09de0a66-3156-48b4-90a5-1cf25a905207";
        // 512MB Standard Instance
        const string standardFlavorId = "2";
        var requestedServer = serverService.CreateServer("sample", ubuntuImageId, standardFlavorId,
            networks: new string[] {network.Id});
        serverService.WaitForServerActive(requestedServer.Id);

        Console.WriteLine("Allocating a public IP address...");
        var ip = await rackConnectService.CreatePublicIPAsync(
            new PublicIPCreateDefinition {ShouldRetain = true});
        await ip.WaitUntilActiveAsync();
        Console.WriteLine($"Acquired {ip.PublicIPv4Address}!");

        Console.WriteLine("Assigning the public IP to the sample cloud server...");
        await ip.AssignAsync(requestedServer.Id);
        await ip.WaitUntilActiveAsync();

        Console.WriteLine("Deleting sample cloud server...");
        serverService.DeleteServer(requestedServer.Id);

        Console.WriteLine("Deallocating the public IP address...");
        await ip.DeleteAsync();
    }
开发者ID:rackspace,项目名称:rackspace-net-sdk,代码行数:46,代码来源:AssignPublicIPSamples.cs

示例7: Should_Create_A_Server_With_New_Network_And_Wait_For_Active

        public void Should_Create_A_Server_With_New_Network_And_Wait_For_Active()
        {
            var provider = new CloudServersProvider(_testIdentity);
            var networks = new List<Guid>() { new Guid(_created_network_id2) };
            var testServer = provider.CreateServer("net-sdk-test-server", "d531a2dd-7ae9-4407-bb5a-e5ea03303d98", "2", networks: networks);

            Assert.IsNotNull(testServer.Id);
            _created_server_id = testServer.Id;

            var serverDetails = provider.WaitForServerActive(_created_server_id);
            Assert.AreEqual("ACTIVE", serverDetails.Status);
        }
开发者ID:jasonmitschke,项目名称:openstack.net,代码行数:12,代码来源:CloudNetworksTests.cs

示例8: Main

        static void Main(string[] args)
        {
            Console.WriteLine();
            if (ParseArguments(args))
            {
                Console.WriteLine("Logging in...");

                if (Login())
                {
                    var cloudServers = new CloudServersProvider(auth);

                    var newServerList = new List<NewServer>();
                    var serversToBuild = 3;

                    var completedServers = 0;
                    var cursorPos = 0;

                    // keep looping until all servers are finished building, or have returned an error state.
                    while (completedServers < serversToBuild)
                    {
                        try
                        {
                            if (newServerList.Count < serversToBuild)
                            {
                                // build all servers at once
                                for (int i = 0; i < serversToBuild; i++)
                                {
                                    Console.WriteLine(String.Format("Creating server: {0}{1}...", ServerNamePrefix, newServerList.Count+1));

                                    // Create a 512mb cloud server instance using centos 6.0
                                    newServerList.Add(cloudServers.CreateServer(String.Format("{0}{1}", ServerNamePrefix, newServerList.Count+1), "a3a2c42f-575f-4381-9c6d-fcd3b7d07d17", "2", region: ServerRegion));
                                }

                                Console.WriteLine();
                                Console.WriteLine(String.Format(" {0,-2} {1,-10} {2,-14} {3,-15} {4,-10} {5,-21}", "%", "Name", "Password", "IPv4", "Status", "Task"));
                                cursorPos = Console.CursorTop;

                                for (int i = 0; i < newServerList.Count; i++)
                                {
                                    Console.WriteLine();
                                }
                            }

                            completedServers = 0; // avoid duplicate counting
                            for (int i = 0; i < newServerList.Count; i++)
                            {
                                var server = newServerList[i].GetDetails();

                                Console.SetCursorPosition(0, cursorPos +i);
                                Console.WriteLine(String.Format("{0,-3} {1,-10} {2,-14} {3,-15} {4,-10} {5,-21}", server.Progress, server.Name, newServerList[i].AdminPassword, server.AccessIPv4, server.VMState, server.TaskState));

                                if (server.Status == ServerState.ACTIVE || server.Status == ServerState.ERROR)
                                {
                                    completedServers++;
                                }

                                Thread.Sleep(1000);
                            }
                        }
                        catch (Exception ex)
                        {
                            PrintException(ex);
                            return;
                        }

                        Thread.Sleep(1000);
                    }
                }
            }

            Console.WriteLine();
            Console.Write("Press any key to exit");
            Console.ReadKey();
        }
开发者ID:jonwalton,项目名称:cloud_code_samples,代码行数:74,代码来源:Program.cs

示例9: 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 ();
        }
开发者ID:DonSchenck,项目名称:api-site,代码行数:98,代码来源:getting_started.cs

示例10: 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)
                                        {
//.........这里部分代码省略.........
开发者ID:jonwalton,项目名称:cloud_code_samples,代码行数:101,代码来源:Program.cs


注:本文中的CloudServersProvider.CreateServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。