Search in sources :

Example 21 with ComputeService

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

the class TestComputeService method testOpenstackMigrate.

@Ignore
@Test
public void testOpenstackMigrate() throws ZoneException {
    // For testing the migrate functionality
    Properties properties = new Properties();
    String vmId = "75dce20c-97f9-454d-abcc-aa904a33df5a";
    properties.put(ContextFactory.PROPERTY_IDENTITY_URL, "http://135.25.246.131:5000");
    properties.put(ContextFactory.PROPERTY_TENANT, "Play");
    // String vmId = "af51c8b9-3df4-4770-846a-457666367b23";
    // properties.put(ContextFactory.PROPERTY_IDENTITY_URL, "http://135.25.69.195:5000");
    // properties.put(ContextFactory.PROPERTY_TENANT, "Trinity");
    OpenStackContext context = (OpenStackContext) ContextFactory.getContext("OpenStackProvider", properties);
    context.login("AppC", "AppC");
    ComputeService computeService = context.getComputeService();
    Server testVNF = computeService.getServer(vmId);
    long t1, t2, t3, t4;
    t1 = System.currentTimeMillis() / 1000;
    computeService.migrateServer(testVNF.getId());
    testVNF.waitForStateChange(1, 600, Status.PENDING);
    t2 = System.currentTimeMillis() / 1000;
    System.out.println("Migrate accepted and calculating prep work");
    try {
        computeService.migrateServer(testVNF.getId());
        fail("Should not be able to migrate a server that is in PENDING");
    } catch (Exception e) {
    // Good
    }
    try {
        computeService.processResize(testVNF);
        fail("Should not be able to confirm a resize on a server that is in PENDING");
    } catch (Exception e) {
    // Good
    }
    testVNF.waitForStateChange(5, 600, Status.READY);
    t3 = System.currentTimeMillis() / 1000;
    System.out.println("Migrate calculations does. Send resizeConfirm to apply");
    computeService.processResize(testVNF);
    testVNF.waitForStateChange(1, 600, Status.RUNNING);
    t4 = System.currentTimeMillis() / 1000;
// System.out.println("Migrate Complete. Time to: 1) Start checking after migrate() call, 2) Finish checking, 3) Commit migrate");
// System.out.println(String.format("1) %3ds\n2) %3ds (%03ds)\n3) %3ds (%3ds)", t2 - t1, t3 - t2, t3 - t1,
// t4 - t3, t4 - t1));
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) Server(com.att.cdp.zones.model.Server) Properties(java.util.Properties) ComputeService(com.att.cdp.zones.ComputeService) ZoneException(com.att.cdp.exceptions.ZoneException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with ComputeService

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

the class TestSecurityGroups method testAll.

@Test
@Ignore
public void testAll() throws ZoneException {
    Context context = connect();
    ComputeService service = context.getComputeService();
    String aclName = "Unit Test ACL";
    try {
        ACL template = new ACL();
        template.setName(aclName);
        template.setDescription(aclName);
        ACL acl = service.createAccessControlList(template);
        assertNotNull(acl);
        assertTrue(acl.getRules().isEmpty());
        Rule rule1 = new Rule(Rule.PROTOCOL.TCP, 80, 80, "0.0.0.0/0");
        Rule rule2 = new Rule(Rule.PROTOCOL.UDP, 60000, 60010, "0.0.0.0/0");
        rule1 = service.addACLRule(acl.getId(), rule1);
        assertNotNull(rule1.getId());
        rule2 = service.addACLRule(acl.getId(), rule2);
        assertNotNull(rule2.getId());
        acl = service.getAccessControlList(acl.getId());
        assertEquals(2, acl.getRules().size());
        assertEquals(Rule.PROTOCOL.TCP, acl.getRules().get(0).getProtocol());
        assertEquals(Rule.PROTOCOL.UDP, acl.getRules().get(1).getProtocol());
        service.deleteACLRule(rule1);
        acl = service.getAccessControlList(acl.getId());
        assertEquals(1, acl.getRules().size());
        assertEquals(Rule.PROTOCOL.UDP, acl.getRules().get(0).getProtocol());
        service.deleteACLRule(rule2);
        acl = service.getAccessControlList(acl.getId());
        assertTrue(acl.getRules().isEmpty());
        service.deleteAccessControlList(acl.getId());
        try {
            service.getAccessControlList(acl.getId());
            fail("Failed to delete the ACL");
        } catch (ZoneException ze) {
        // Successfully deleted the ACL
        }
    } catch (ZoneException ze) {
        ze.printStackTrace();
        fail();
    }
}
Also used : Context(com.att.cdp.zones.Context) ZoneException(com.att.cdp.exceptions.ZoneException) ACL(com.att.cdp.zones.model.ACL) Rule(com.att.cdp.zones.model.Rule) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with ComputeService

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

the class OpenStackServer method loadHypervisorAttachment.

/**
 * This method is called to load the hypervisor attachment, if it has not already been loaded. If it has been
 * loaded, then the call is ignored.
 *
 * @param context
 *            The context that represents the connection we are servicing
 * @throws ZoneException
 *             If the attachments cannot be obtained, or if a hypervisor cannot be listed, or a hypervisor does not
 *             exist
 */
private void loadHypervisorAttachment(Context context) throws ZoneException {
    if (hypervisorAttachmentProcessed.compareAndSet(false, true)) {
        ComputeService computeService = context.getComputeService();
        List<Hypervisor> hypervisors = computeService.getHypervisors();
        if (this.novaModel.getHypervisorHostname() != null && !this.novaModel.getHypervisorHostname().isEmpty()) {
            String hypervisorName = this.novaModel.getHypervisorHostname();
            for (Hypervisor h : hypervisors) {
                if (h.getHostName().equals(hypervisorName)) {
                    this.setHypervisor(h);
                    return;
                }
            }
        }
    }
}
Also used : Hypervisor(com.att.cdp.zones.model.Hypervisor) ComputeService(com.att.cdp.zones.ComputeService)

Example 24 with ComputeService

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

the class ConnectedServer method getPorts.

/**
 * Override the API class to actually get and return the list of ports from the service provider and to cache them
 * once obtained.
 *
 * @see com.att.cdp.zones.model.Server#getPorts()
 */
@Override
public List<Port> getPorts() throws ZoneException {
    Context context = getContext();
    ComputeService service = context.getComputeService();
    List<Port> ports = service.getPorts(this);
    if (ports == null) {
        ports = new ArrayList<Port>();
    }
    return ports;
}
Also used : Context(com.att.cdp.zones.Context) Port(com.att.cdp.zones.model.Port) ComputeService(com.att.cdp.zones.ComputeService)

Example 25 with ComputeService

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

the class ConnectedServer method detachPort.

/**
 * @see com.att.cdp.zones.model.Server#detachPort(com.att.cdp.zones.model.Port)
 */
@Override
public void detachPort(Port port) throws ZoneException {
    Context context = getContext();
    ComputeService service = context.getComputeService();
    service.detachPort(this, port);
}
Also used : Context(com.att.cdp.zones.Context) ComputeService(com.att.cdp.zones.ComputeService)

Aggregations

ComputeService (com.att.cdp.zones.ComputeService)25 Context (com.att.cdp.zones.Context)21 Ignore (org.junit.Ignore)18 Test (org.junit.Test)16 Server (com.att.cdp.zones.model.Server)12 OpenStackContext (com.att.cdp.openstack.OpenStackContext)10 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)6 Port (com.att.cdp.zones.model.Port)4 NetworkService (com.att.cdp.zones.NetworkService)3 Hypervisor (com.att.cdp.zones.model.Hypervisor)3 Volume (com.att.cdp.zones.model.Volume)3 ZoneException (com.att.cdp.exceptions.ZoneException)2 VolumeService (com.att.cdp.zones.VolumeService)2 ACL (com.att.cdp.zones.model.ACL)2 Template (com.att.cdp.zones.model.Template)2 GlanceConnector (com.att.cdp.openstack.connectors.GlanceConnector)1 NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)1 QuantumConnector (com.att.cdp.openstack.connectors.QuantumConnector)1 OpenStackComputeService (com.att.cdp.openstack.v2.OpenStackComputeService)1 IdentityService (com.att.cdp.zones.IdentityService)1