-
Notifications
You must be signed in to change notification settings - Fork 4
1. Getting started
If you use Maven or Gradle, you can simply add the CLC SDK as a dependency.
Maven:
<dependencies>
<dependency>
<groupId>com.centurylink.cloud</groupId>
<artifactId>java-sdk</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
Gradle:
compile 'com.centurylink.cloud:java-sdk:1.2.2'
Next, you need to create an SDK instance:
ClcSdk sdk = new ClcSdk(
new StaticCredentialsProvider("john.doe", "hey@WMe8u")
);
Now that you've been authorized, you can go on and create your first server.
ServerService.create(CreateServerConfig config)
creates a new server with all the necessary parameters, such as name, group, OS, disks settings, etc. These parameters need to be specified beforehand using the CreateServerConfig
config. For example:
sdk
.serverService()
.create(new CreateServerConfig()
.name("SERVER")
.description("My First Server")
.type(STANDARD)
.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)
)
)
.template(Template.refByOs()
.dataCenter(DE_FRANKFURT)
.type(CENTOS)
.version("6")
.architecture(x86_64)
)
.network(new NetworkConfig()
.primaryDns("172.17.1.26")
.secondaryDns("172.17.1.27")
.publicIp(new PublicIpConfig()
.openPorts(8080)
)
)
)
.waitUntilComplete()
Now that you have a server, you can use the server-searching functionality to get all the necessary information about it (see the next section).
ServerService.find(ServerFilter filter)
can be used to look for server data. ServerFilter
can
find severs by ID, name, datacenter, group, etc. Here is how it works:
List<ServerMetadata> servers = serverService
.find(new ServerFilter()
.dataCenters(DE1_FRANKFURT)
.descriptionContains("My First Server")
);
Now the servers
variable contains a single item with attributes of a previously created server.
In addition to searching, you can perform different power operations on your server (see the next section).
The SDK supports various server operations for single servers and groups of servers. Here is the list of methods available for a single server:
- Power on a server (
ServerService.powerOn
) - Power off a server (
ServerService.powerOff
) - Archive a server (
ServerService.archive
) - Restore a server from an archive (
ServerService.restore
) - Create a snapshot of a server (
ServerService.createSnapshot
) - Delete a snapshot of a server (
ServerService.deleteSnapshot
) - Revert a server to a snapshot (
ServerService.revertToSnapshot
) - Restart a server (
ServerService.restart
) - Pause a server (
ServerService.pause
) - Reset a server (
ServerService.reset
) - Start the maintenance mode on a single server (
ServerService.startMaintenance
) - Stop the maintenance mode on a single server (
ServerService.stopMaintenance
)
And here are some examples of how to use these methods:
Server serverRef = Server.refByDescription()
.dataCenter(DE_FRANKFURT)
.description("My First Server");
Server otherServerRef = Server.refById("DE1ALTDSERV101");
To specify a target server, you may use server references. This abstraction makes it possible to filter one unique instance from a set of servers.
serverService.powerOn(serverRef);
serverService.startMaintenance(serverRef);
serverService.pause(serverRef);
For more information on operations available for single servers and groups of servers, refer to Server actions and Group actions.
- [Getting Started] (./1.-Getting-started)
- User Guide - Basic Functions
- Server management
- Server actions
- Managing groups
- Group actions
- Searching templates
- Searching data centers
- Invoice statistics
- SDK configuration
- User Guide - Advanced Functions
- Configuring remote servers over SSH
- Defining a group hierarchy
- Billing statistics
- Server monitoring statistics
- Policies management
- Shared load balancers management
- User Guide - Framework adapters