Search in sources :

Example 91 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackVolumeService method createSnapshot.

/**
 * This method is used to create a new snapshot using the Snapshot object (disconnected) as the model. When the
 * method returns, a connected model object is returned that should be used for any model navigation desired.
 *
 * @param template
 *            The template of the snapshot to create. This must contain at least a name and volumeId. Other
 *            information will be supplied if not present. Any ID is ignored, and the ID of the created snapshot is
 *            returned in the connected snapshot object returned to the caller.
 * @return A Snapshot object that is connected to the service context and can be used to navigate the model.
 * @throws ZoneException
 *             - If the snapshot cannot be created for some reason.
 * @see com.att.cdp.zones.VolumeService#createSnapshot(com.att.cdp.zones.model.Snapshot)
 */
@SuppressWarnings("nls")
@Override
public Snapshot createSnapshot(Snapshot template) throws ZoneException {
    checkArg(template, "template");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, template.getName());
    RequestState.put(RequestState.VOLUME, template.getVolumeId());
    RequestState.put(RequestState.SERVICE, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    try {
        com.woorea.openstack.cinder.model.SnapshotForCreate newSnapshot = new com.woorea.openstack.cinder.model.SnapshotForCreate();
        HashMap<String, String> dictionary = new HashMap<>();
        dictionary.put("name", "name");
        dictionary.put("description", "description");
        dictionary.put("size", "size");
        dictionary.put("volumeId", "volumeId");
        ObjectMapper.map(template, newSnapshot, dictionary);
        OpenStackSnapshot snapshot = new OpenStackSnapshot(context, cinder.getClient().snapshots().create(newSnapshot).execute());
        return snapshot;
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // for the compiler
    return null;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) HashMap(java.util.HashMap) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot)

Example 92 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class TestComputeService method testAttachAndDetachPorts.

/**
 * Test the attach and detach of a port
 *
 * @throws ZoneException
 *             if the test fails
 */
@SuppressWarnings("nls")
@Test
@Ignore
public void testAttachAndDetachPorts() throws ZoneException {
    Context context = connect();
    ComputeService compute = context.getComputeService();
    NetworkService network = context.getNetworkService();
    /*
		 * Get a list of servers. Make sure that at least one server exists.
		 * We'll just use the first one we find.
		 */
    List<Server> servers = compute.getServers();
    assertNotNull(servers);
    assertFalse(servers.isEmpty());
    Server server = servers.get(0);
    // 
    /*
		 * Now, get the ports attached to that server. Make sure there is at
		 * least one port. We'll use the first one we find.
		 */
    List<Port> ports = server.getPorts();
    assertNotNull(ports);
    assertFalse(ports.isEmpty());
    /*
		 * Use the first port to model the creation of a new port. We'll use the
		 * same subnet.
		 */
    Port modelPort = ports.get(0);
    Subnet subnet = network.getSubnetById(modelPort.getSubnetId());
    Port newPort = network.createPort(subnet);
    assertNotNull(newPort);
    assertNotNull(newPort.getMacAddr());
    assertNotNull(newPort.getId());
    /*
		 * Save the new port's ID. We'll use that to test that it was actually
		 * attached and detached
		 */
    String id = newPort.getId();
    /*
		 * Attach the port to the server. Then list all the ports and make sure
		 * the new port is included
		 */
    server.attachPort(newPort);
    ports = server.getPorts();
    boolean found = false;
    for (Port p : ports) {
        if (p.getId().equals(id)) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Port is not listed as attached to the server");
    }
    /*
		 * Now detach the port and make sure that it is NOT listed
		 */
    server.detachPort(newPort);
    try {
        Thread.sleep(1000L);
    } catch (InterruptedException e) {
    // ignore
    }
    ports = server.getPorts();
    found = false;
    for (Port p : ports) {
        if (p.getId().equals(id)) {
            found = true;
            break;
        }
    }
    if (found) {
        fail("Port is still listed as attached to the server");
    }
    /*
		 * Finally, delete the new port
		 */
    network.deletePort(newPort);
}
Also used : Context(com.att.cdp.zones.Context) Server(com.att.cdp.zones.model.Server) Port(com.att.cdp.zones.model.Port) NetworkService(com.att.cdp.zones.NetworkService) Subnet(com.att.cdp.zones.model.Subnet) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 93 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class TestComputeService method testInvalidRebootType.

@Ignore
@Test(expected = InvalidRequestException.class)
public void testInvalidRebootType() throws ZoneException {
    Context context = connect();
    ComputeService compute = context.getComputeService();
    // NetworkService network = context.getNetworkService();
    List<Server> ids = compute.getServers();
    for (Server id : ids) {
        compute.rebootServer(id, "SOFT1");
    }
}
Also used : Context(com.att.cdp.zones.Context) Server(com.att.cdp.zones.model.Server) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class TestComputeService method testHardRebootService.

@Ignore
public void testHardRebootService() throws ZoneException {
    Context context = connect();
    ComputeService compute = context.getComputeService();
    // NetworkService network = context.getNetworkService();
    List<Server> servers = compute.getServers();
    Server server = servers.get(0);
    compute.rebootServer(server, "HARD");
    assertTrue(server.getStatus().equals("HARD_REBOOT"));
}
Also used : Context(com.att.cdp.zones.Context) Server(com.att.cdp.zones.model.Server) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore)

Example 95 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class TestComputeService method testSoftRebootService.

@Ignore
public void testSoftRebootService() throws ZoneException {
    Context context = connect();
    ComputeService compute = context.getComputeService();
    // NetworkService network = context.getNetworkService();
    List<Server> servers = compute.getServers();
    Server server = servers.get(0);
    compute.rebootServer(server, "SOFT");
    assertTrue(server.getStatus().equals("REBOOT"));
}
Also used : Context(com.att.cdp.zones.Context) Server(com.att.cdp.zones.model.Server) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore)

Aggregations

Context (com.att.cdp.zones.Context)248 OpenStackContext (com.att.cdp.openstack.OpenStackContext)167 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)140 ArrayList (java.util.ArrayList)55 Ignore (org.junit.Ignore)50 Test (org.junit.Test)47 Quantum (com.woorea.openstack.quantum.Quantum)35 ZoneException (com.att.cdp.exceptions.ZoneException)30 NetworkService (com.att.cdp.zones.NetworkService)24 Server (com.att.cdp.zones.model.Server)22 ComputeService (com.att.cdp.zones.ComputeService)21 Network (com.att.cdp.zones.model.Network)19 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)18 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 Subnet (com.att.cdp.zones.model.Subnet)15 Port (com.att.cdp.zones.model.Port)14 Snapshot (com.att.cdp.zones.model.Snapshot)12 Volume (com.att.cdp.zones.model.Volume)11 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)11 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)10