Пример #1
0
        public async Task <Server> CreateServer(ServerCreateDefinition definition)
        {
            var server = await _compute.CreateServerAsync(definition);

            Register(server);
            return(server);
        }
Пример #2
0
        public async Task CreateServerGroup_AndAssociateAServerTest()
        {
            ServerGroupDefinition definition = _testData.BuildServerGroup();

            Trace.WriteLine($"Creating server group named: {definition.Name}");
            ServerGroup serverGroup = await _testData.CreateServerGroup(definition);

            Trace.WriteLine("Verifying server group matches requested definition...");
            Assert.NotNull(serverGroup);
            Assert.Equal(definition.Name, serverGroup.Name);
            Assert.Equal(definition.Policies, serverGroup.Policies);

            Trace.WriteLine("Creating a server associated with the group...");
            ServerCreateDefinition serverDefinition = _testData.BuildServer();

            serverDefinition.SchedulerHints = new SchedulerHints();
            serverDefinition.SchedulerHints.Add("group", serverGroup.Id);
            var server = await _testData.CreateServer(serverDefinition);

            await server.WaitUntilActiveAsync();

            Trace.WriteLine("Verifying the server is a member of the group...");
            serverGroup = await _compute.GetServerGroupAsync(serverGroup.Id);

            Assert.Contains(server.Id, serverGroup.Members);

            Trace.WriteLine("Deleting the server group...");
            await serverGroup.DeleteAsync();

            var groups = await _compute.ListServerGroupsAsync();

            Assert.DoesNotContain(serverGroup.Id, groups.Select(x => x.Id));
        }
Пример #3
0
        public void SerializeServerWithoutSchedulerHints()
        {
            string expectedJson = JObject.Parse(@"{'server':{'name':'name','imageRef':'00000000-0000-0000-0000-000000000000','flavorRef':'00000000-0000-0000-0000-000000000000'}}")
                .ToString(Formatting.None);
            var server = new ServerCreateDefinition("name", Guid.Empty, Guid.Empty);

            var json = OpenStackNet.Serialize(server);
            Assert.Equal(expectedJson, json);
        }
Пример #4
0
        public void SerializeServerWithoutSchedulerHints()
        {
            string expectedJson = JObject.Parse(@"{'server':{'name':'name','imageRef':'00000000-0000-0000-0000-000000000000','flavorRef':'00000000-0000-0000-0000-000000000000'}}")
                                  .ToString(Formatting.None);
            var server = new ServerCreateDefinition("name", Guid.Empty, Guid.Empty);

            var json = OpenStackNet.Serialize(server);

            Assert.Equal(expectedJson, json);
        }
Пример #5
0
    public async Task Run(string identityEndpoint, string username, string password, string project, string region)
    {
        // Configure authentication
        var user = new CloudIdentityWithProject
        {
            Username = username,
            Password = password,
            ProjectName = project
        };
        var identity = new OpenStackIdentityProvider(new Uri(identityEndpoint), user);
        var compute = new ComputeService(identity, region);

        Console.WriteLine("Looking up the tiny flavor...");
        var flavors = await compute.ListFlavorsAsync();
        var tinyFlavor = flavors.FirstOrDefault(x => x.Name.Contains("tiny"));
        if(tinyFlavor == null) throw new Exception("Unable to find a flavor with the 'tiny' in the name!");

        Console.WriteLine("Looking up the cirros image...");
        var images = await compute.ListImagesAsync(new ImageListOptions {Name = "cirros"});
        var cirrosImage = images.FirstOrDefault();
        if(cirrosImage == null) throw new Exception("Unable to find an image named 'cirros'");

        Console.WriteLine("Creating Sample server... ");
        var serverDefinition = new ServerCreateDefinition("sample", cirrosImage.Id, tinyFlavor.Id);
        var server = await compute.CreateServerAsync(serverDefinition);

        Console.WriteLine("Waiting for the sample server to come online...");
        await server.WaitUntilActiveAsync();

        Console.WriteLine("Taking a snaphot of the sample server...");
        var snapshot = await server.SnapshotAsync(new SnapshotServerRequest("sample-snapshot"));
        await snapshot.WaitUntilActiveAsync();

        Console.WriteLine();
        Console.WriteLine("Sample Server Information:");
        Console.WriteLine();
        Console.WriteLine($"Server Id: {server.Id}");
        Console.WriteLine($"Server Name: {server.Name}");
        Console.WriteLine($"Server Status: {server.Status}");
        Console.WriteLine($"Server Address: {server.IPv4Address}");
        Console.WriteLine();
        Console.WriteLine("Sample Snapshot Information:");
        Console.WriteLine();
        Console.WriteLine($"Image Id: {snapshot.Id}");
        Console.WriteLine($"Image Name: {snapshot.Name}");
        Console.WriteLine($"Image Status: {snapshot.Status}");
        Console.WriteLine($"Image Type: {snapshot.Type}");
        Console.WriteLine();

        Console.WriteLine("Deleting Sample Server...");
        await snapshot.DeleteAsync();
        await server.DeleteAsync();
    }
Пример #6
0
        public void SerializeServerWithSchedulerHints()
        {
            string expectedJson = JObject.Parse(@"{'server':{'name':'name','imageRef':'00000000-0000-0000-0000-000000000000','flavorRef':'00000000-0000-0000-0000-000000000000'},'os:scheduler_hints':{'group':'groupId'}}")
                                  .ToString(Formatting.None);
            var server = new ServerCreateDefinition("name", Guid.Empty, Guid.Empty);

            server.SchedulerHints = new SchedulerHints();
            server.SchedulerHints.Add("group", "groupId");

            var json = OpenStackNet.Configuration.FlurlHttpSettings.JsonSerializer.Serialize(server);

            Assert.Equal(expectedJson, json);
        }
Пример #7
0
        public void CreateServer()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverId = Guid.NewGuid();
                httpTest.RespondWithJson(new Server {Id = serverId});

                var definition = new ServerCreateDefinition("{name}", Guid.NewGuid(), "{flavor-id}");
                var result = _compute.CreateServer(definition);

                httpTest.ShouldHaveCalled("*/servers");
                Assert.NotNull(result);
                Assert.Equal(serverId,result.Id);
                Assert.IsType<ComputeApi>(((IServiceResource)result).Owner);
            }
        }
Пример #8
0
        public void CreateServer()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverId = Guid.NewGuid();
                httpTest.RespondWithJson(new Server {
                    Id = serverId
                });

                var definition = new ServerCreateDefinition("{name}", Guid.NewGuid(), "{flavor-id}");
                var result     = _compute.CreateServer(definition);

                httpTest.ShouldHaveCalled("*/servers");
                Assert.NotNull(result);
                Assert.Equal(serverId, result.Id);
                Assert.IsType <ComputeApi>(((IServiceResource)result).Owner);
            }
        }
Пример #9
0
 /// <inheritdoc cref="ComputeApi.CreateServerAsync{T}" />
 public Task <Server> CreateServerAsync(ServerCreateDefinition server, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_computeApi.CreateServerAsync <Server>(server, cancellationToken));
 }
 public async Task<Server> CreateServer(ServerCreateDefinition definition)
 {
     var server = await _compute.CreateServerAsync(definition);
     Register(server);
     return server;
 }
 /// <inheritdoc cref="ComputeService.CreateServerAsync" />
 public static Server CreateServer(this ComputeService service, ServerCreateDefinition server)
 {
     return service.CreateServerAsync(server).ForceSynchronous();
 }