Skip to content

2.1 Server management

Sergey Fedosenko edited this page Feb 4, 2016 · 13 revisions

This section overviews server management features available in the SDK. Note that in all examples serverService refers to the new ClcSdk().serverService() variable.

Creating servers

You can asynchronously create a server using the CreateServerConfig command. To get the result of the operation, call waitUntilComplete().getResult(). The table below contains the list of available parameters.

Name Type Description Required
name string The name of the server to be created. Use alphanumeric characters and dashes only. The name must be 1–8 characters long depending on the length of the account alias. The combined length of the account alias and server name must be no more than 10 characters. (This name will be appended with a two-digit number and prepended with the data center code and account alias to make up the final server name.) Yes
description string A user-defined description of the server No
group Group A parent group reference Yes
template Template A template reference Yes
machine Machine Here, you can set the number of CPU cores, as well as RAM (in GB), anti-affinity policy and disks configuration. Yes
password String The password of the administrator or root user on the server. If no password is provided, it will be generated automatically. No
managedOS bool This determines whether the server to be created will be managed or not. The default value is false. No
network NetworkConfig The network configuration. You may use it to configure the network reference, primary and secondary DNS, and public IP. If no values are provided, the network will be chosen automatically. If your account does not yet have a network assigned to it, leave this blank and one will be assigned automatically. No
type ServerType This determines what type of server will be created: standard or hyperscale. The two possible values are STANDARD and HYPERSCALE. The default is STANDARD. Yes
storageType StorageType StorageType determines the type of storage for standard servers: standard or premium. Standard storage will be used by default if no value is provided. Note that for hyperscale servers the storage type must be set to hyperscale. No
timeToLive TimeToLive Sets the date and time when the server will be deleted. The default format is YYYY-MM-DDThh:mm+hh:mm No
customFields List Collection of custom field ID-value pairs to set for the server. No
Below is an example of how these parameters can be used when creating a new server: ``` java OperationFuture future = serverService .create(new CreateServerConfig() .name("TCRT") .type(STANDARD) .storageType(PREMIUM) .password("serverPass") .group(Group.refByName() .name(DEFAULT_GROUP) .dataCenter(DataCenter.refByName("FranKfUrt")) ) .timeToLive(ZonedDateTime.now().plusDays(1)) .machine(new Machine() .cpuCount(1) .ram(3) .disk(new DiskConfig() .type(DiskType.RAW) .size(14) ) .antiAffinityPolicy(AntiAffinityPolicy.refByName() .name("Policy CA3") .dataCenter(CA_TORONTO_2) ) ) .template(Template.refByOs() .dataCenter(DE_FRANKFURT) .type(CENTOS) .version("6") .architecture(x86_64) ) .network(new NetworkConfig() //add the next line only if you want to select the network with concrete id otherwise network will be selected automatically .network(new IdNetworkRef(DE_FRANKFURT, "fbc1f6c7dd0241dfa22bafa05244da00")) .primaryDns("172.17.1.26") .secondaryDns("172.17.1.27") .publicIpConfig(new CreatePublicIpConfig() .openPorts(8080) ) ) .customFields( new CustomField().name("Approved by").value("Bob Smith"), new CustomField("Type", "1") ) );

ServerMetadata result = future.waitUntilComplete().getResult();


Modifying servers
-----------------
You can asynchronously modify an existing server using `ModifyServerConfig`. To get the result of the operation, call: `waitUntilComplete().getResult()`. See the table below for the list of available config parameters.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody>
<tr>
<td>groupId</td>
<td>string</td>
<td>A new parent group ID</td>
<td>No</td>
</tr>
<tr>
<td>description</td>
<td>string</td>
<td>A new server description</td>
<td>No</td>
</tr>
<tr>
<td>machineConfig</td>
<td>Machine</td>
<td>A new config that contains new data on the CPU (number of cores), RAM (in GB), and disks configuration.</td>
<td>No</td>
</tr>
<tr>
<td>credentialsConfig</td>
<td>CredentialsConfig</td>
<td>A new password</td>
<td>No</td>
</tr>
<tr>
<td>customFields</td>
<td>List<CustomField></td>
<td>Collection of custom field ID-value pairs to set for the server.</td>
<td>No</td>
</tr>
</table>
Here is an example of how these parameters can be used to modify an existing server:
``` java
OperationFuture<Server> future = 
serverService.modify(serverRef,
    new ModifyServerConfig()
        .machineConfig(new Machine()
           .cpuCount(4)
               .ram(16)
               .disk(
                   new DiskConfig().diskId("0:0").size(1)
               )
               .disk(
                   new DiskConfig().diskId("0:1").size(2)
               )
               .disk(
                   new DiskConfig().diskId("0:2").size(3)
               )
        )
        .description("New machine description")
        .customFields(
            new CustomField().name("Approved by").value("test user"),
            new CustomField().name("Type").value("0")
        )
    );

Searching servers

You can find servers by various search criteria, such as data centers, groups, server status, and server reference, which can be defined by a server ID or server description. The result of this search will be a list of ServerMetadata similar to this:

List<ServerMetadata> result = 
serverService
    .find(new ServerFilter()
        .dataCenters(dataCenter1, dataCenter2)
        .dataCentersWhere(d -> d.getGroup().equals("groupId"))
        .groupId("group1", "group2")
        .groups(Group.refByName()
            .dataCenter(DataCenter.US_EAST_NEW_YORK)
            .name("MyServers")
        )
        .groupsWhere(g -> g.getType().equals("default"))
        .status("active", "archived")
        .id("DE1ALTDTCRT154", "DE1ALTDTCRT155")
        .where(s -> s.getDetails().getInMaintenanceMode())
    );
    

Deleting servers

You may delete a single server with:

OperationFuture<Server> future = serverService.delete(newServer);

To delete a set of servers, use:

OperationFuture<List<Server>> future = 
serverService
    .delete(
        Server.refById("DE1ALTDTCRT154"),
        Server.refById("DE1ALTDTCRT155")
    );
    

To delete a set of servers specified by some search criteria, use:

OperationFuture<List<Server>> future = 
serverService
    .delete(new ServerFilter()
        .dataCenters(DataCenter.US_WEST_SEATTLE)
        .onlyActive()
    );
    

To see the result of the operation, call: waitUntilComplete().getResult().

Public IP

Adding public IPs

To add a public IP to your server, use:

serverService
    .addPublicIp(serverRef,
        new CreatePublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );

To add public IPs for multiple servers specified by a reference, use:

serverService
    .addPublicIp(
        asList(
            serverRef1, serverRef2
        ),
        new CreatePublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );

You can also add public IPs for multiple servers specified by a server filter.

serverService
    .addPublicIp(
        new ServerFilter()
            .dataCenters(DataCenter.US_WEST_SEATTLE)
            .onlyActive(),
        new CreatePublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );

To get the result of the operation, call: waitUntilComplete().getResult().

Searching public IPs

You can find all public IPs for a server using:

List<PublicIpMetadata> publicIps = serverService.findPublicIp(serverRef);

Modifying public IPs

It is possible to modify all public IPs (in 90% of cases it will be just one IP) for multiple servers specified by a reference. Here is how to do this:

serverService
    .modifyPublicIp(serverRef,
        new ModifyPublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );
    
serverService
    .modifyPublicIp(
        asList(
            serverRef1, serverRef2
        ),
        new ModifyPublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );
    
serverService
    .modifyPublicIp(
        new ServerFilter()
            .dataCenters(DataCenter.US_WEST_SEATTLE)
            .onlyActive(),
        new ModifyPublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );

If you want to update a specified public IP, call the method provided below. Note that you will need to specify a server reference, an existing public IP (String), and the new config.

serverService
    .modifyPublicIp(
        serverRef, publicIP, 
        new ModifyPublicIpConfig()
            .openPorts(PortConfig.HTTPS, PortConfig.HTTP)
            .sourceRestrictions("70.100.60.140/32")
    );

Deleting public IPs

To delete all public IPs or a specified IP of a server, use:

// remove all public IPs of the specified server
serverService.removePublicIp(serverRef);

// remove a specified public IP of some server
serverService.removePublicIp(serverRef, publicIp);

You can also delete public IPs by a server reference or server filter.

serverService.removePublicIp(serverRef1, serverRef2);

serverService.removePublicIp(new ServerFilter().status(ACTIVE));

Secondary Network

Adding secondary network

To add a secondary network to your server, use:

serverService
    .addSecondaryNetwork(serverRef,
        new AddNetworkConfig()
            .network(Network.refById("fbc1f6c7dd0241dfa22bafa05244da00"))
            .ipAddress("123.456.1.1")
    );

To add secondary network for multiple servers specified by a reference, use:

serverService
    .addSecondaryNetwork(
        asList(
            serverRef1, serverRef2
        ),
        new AddNetworkConfig()
            .network(Network.refById("fbc1f6c7dd0241dfa22bafa05244da00"))
            .ipAddress("123.456.1.1")
    );

You can also add secondary network for multiple servers specified by a server filter.

serverService
    .addSecondaryNetwork(
        new ServerFilter()
            .dataCenters(DataCenter.US_WEST_SEATTLE)
            .onlyActive(),
        new AddNetworkConfig()
            .network(Network.refById("fbc1f6c7dd0241dfa22bafa05244da00"))
            .ipAddress("123.456.1.1")
    );

To get the result of the operation, call: waitUntilComplete().getResult().

Deleting secondary network

To delete secondary networks, use:

// remove all secondary networks of the specified server
serverService.removeSecondaryNetworks(serverRef);

// remove a specified secondary network of some server
serverService.removeSecondaryNetwork(serverRef, Network.refById("f49875b17cee4b8c99bf1ab75aa286d6"));

You can also delete secondary networks by a server reference or server filter.

serverService.removeSecondaryNetworks(serverRef1, serverRef2);

serverService.removeSecondaryNetworks(new NetworkFilter().dataCenters(DE_FRANKFURT));