| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.cloudsigma.util; |
| 20 | |
| 21 | import org.jclouds.cloudsigma.CloudSigmaClient; |
| 22 | import org.jclouds.cloudsigma.domain.IDEDevice; |
| 23 | import org.jclouds.cloudsigma.domain.Model; |
| 24 | import org.jclouds.cloudsigma.domain.NIC; |
| 25 | import org.jclouds.cloudsigma.domain.Server; |
| 26 | import org.jclouds.cloudsigma.domain.VNC; |
| 27 | |
| 28 | import com.google.common.collect.ImmutableMap; |
| 29 | import com.google.common.collect.ImmutableSet; |
| 30 | |
| 31 | /** |
| 32 | * |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | public class Servers { |
| 36 | /** |
| 37 | * Helper to create a small persistent server |
| 38 | * |
| 39 | * @param name |
| 40 | * what to name the server |
| 41 | * @param driveUuuid |
| 42 | * id of the boot drive |
| 43 | * @param vncPassword |
| 44 | * password for vnc |
| 45 | * @return a builder for a persistent 1Ghz 512m server with DHCP enabled network. |
| 46 | */ |
| 47 | public static Server.Builder small(String name, String driveUuuid, String vncPassword) { |
| 48 | return smallWithStaticIP(name, driveUuuid, vncPassword, "auto"); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Helper to create a small persistent server |
| 53 | * |
| 54 | * @param name |
| 55 | * what to name the server |
| 56 | * @param driveUuuid |
| 57 | * id of the boot drive |
| 58 | * @param vncPassword |
| 59 | * password for vnc |
| 60 | * @param ip |
| 61 | * static IP |
| 62 | * @return a builder for a persistent 1Ghz 512m server with DHCP enabled network. |
| 63 | */ |
| 64 | public static Server.Builder smallWithStaticIP(String name, String driveUuuid, String vncPassword, String ip) { |
| 65 | return new Server.Builder().name(name).cpu(1000).mem(512).persistent(true) |
| 66 | .devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(driveUuuid).build())) |
| 67 | .bootDeviceIds(ImmutableSet.of("ide:0:0")) |
| 68 | .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp(ip).build())) |
| 69 | .vnc(new VNC(null, vncPassword, false)); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Takes the input server and changes its primary ip to a new address. To make this happen, |
| 74 | * you'll need to invoke {@link CloudSigmaClient#setServerConfiguration} |
| 75 | * |
| 76 | * @param in |
| 77 | * server to change |
| 78 | * @param ip |
| 79 | * new ip address |
| 80 | * @return server with its primary nic set to the new address. |
| 81 | */ |
| 82 | public static Server changeIP(Server in, String ip) { |
| 83 | return Server.Builder.fromServer(in).nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp(ip).build())) |
| 84 | .build(); |
| 85 | } |
| 86 | } |