Search in sources :

Example 6 with Port

use of com.att.cdp.zones.model.Port in project AJSC by att.

the class TestNetworkService method testCreateAndDeletePort.

/**
 * Tests that we can create and delete a port
 *
 * @throws ZoneException
 *             If the test cannot connect to the provider
 */
@Test
@Ignore
public void testCreateAndDeletePort() throws ZoneException {
    Context context = connect();
    NetworkService service = context.getNetworkService();
    List<Subnet> subnets = service.getSubnets();
    assertNotNull(subnets);
    assertFalse(subnets.isEmpty());
    Subnet subnet = subnets.get(0);
    Port port = service.createPort(subnet);
    assertNotNull(port);
    assertEquals(port.getSubnetId(), subnet.getId());
    assertNotNull(port.getMacAddr());
    assertNotNull(port.getId());
    assertNotNull(port.getNetwork());
    service.deletePort(port);
}
Also used : Context(com.att.cdp.zones.Context) Port(com.att.cdp.zones.model.Port) NetworkService(com.att.cdp.zones.NetworkService) Subnet(com.att.cdp.zones.model.Subnet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with Port

use of com.att.cdp.zones.model.Port in project AJSC by att.

the class TestNetworkService method testGetPorts.

/**
 * Verifies that we can get ports
 *
 * @throws ZoneException
 *             If the connection fails, user is not authorized, or the provider cannot perform the operation.
 */
@Test
@Ignore
public void testGetPorts() throws ZoneException {
    Context context = connect();
    NetworkService service = context.getNetworkService();
    List<Port> ports = service.getPorts();
    assertNotNull(ports);
    assertFalse(ports.isEmpty());
}
Also used : Context(com.att.cdp.zones.Context) Port(com.att.cdp.zones.model.Port) NetworkService(com.att.cdp.zones.NetworkService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Port

use of com.att.cdp.zones.model.Port in project AJSC by att.

the class OpenStackComputeService method getPorts.

/**
 * Gets the ports connected to a specific server
 *
 * @throws ZoneException
 *             If the server is null or invalid, if the context is closed, or if the context has not been
 *             authenticated, or if the authentication has expired
 * @see com.att.cdp.zones.ComputeService#getPorts(com.att.cdp.zones.model.Server)
 */
@Override
public List<Port> getPorts(Server server) throws ZoneException {
    checkArg(server, "server");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVER, server.getId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    List<Port> list = new ArrayList<>();
    try {
        InterfaceAttachments attachments = nova.getClient().servers().listInterfaceAttachments(server.getId()).execute();
        for (InterfaceAttachment attachment : attachments.getList()) {
            OpenStackPort port = new OpenStackPort(getContext(), attachment);
            list.add(port);
        }
    } catch (OpenStackConnectException | OpenStackResponseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return list;
}
Also used : OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) InterfaceAttachments(com.woorea.openstack.nova.model.InterfaceAttachments) InterfaceAttachment(com.woorea.openstack.nova.model.InterfaceAttachment) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) ArrayList(java.util.ArrayList) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 9 with Port

use of com.att.cdp.zones.model.Port in project AJSC by att.

the class OpenStackComputeService method deleteServer.

/**
 * Delete the specified server using it's id.
 *
 * @param serverId
 *            The server to be deleted.
 * @throws ZoneException
 *             If the server does not exist or cannot be deleted for some reason.
 * @see com.att.cdp.zones.ComputeService#deleteServer(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void deleteServer(String serverId) throws ZoneException {
    checkArg(serverId, "serverId");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVER, serverId);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        Server server = getServer(serverId);
        Server.Status status = server.getStatus();
        RequestState.put(RequestState.STATUS, status.toString());
        if (status.equals(Server.Status.RUNNING) || status.equals(Server.Status.READY) || status.equals(Server.Status.ERROR)) {
            List<Port> ports = server.getPorts();
            for (Port port : ports) {
                port.delete();
            }
            nova.getClient().servers().delete(serverId).execute();
        } else {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId().toString(), status.toString(), StringHelper.asList(Arrays.asList(Server.Status.READY.toString(), Server.Status.RUNNING.toString(), Server.Status.ERROR.toString()))));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
}
Also used : Server(com.att.cdp.zones.model.Server) ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort)

Example 10 with Port

use of com.att.cdp.zones.model.Port in project AJSC by att.

the class OpenStackNetworkService method createPort.

/**
 * @see com.att.cdp.zones.NetworkService#createPort(com.att.cdp.zones.model.Subnet)
 */
@Override
public Port createPort(Subnet subnet) throws ZoneException {
    this.checkArg(subnet, "subnet");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.PORT, subnet.getName());
    RequestState.put(RequestState.SERVICE, "Network");
    RequestState.put(RequestState.SERVICE_URL, quantumConnector.getEndpoint());
    com.woorea.openstack.quantum.model.Port port = new com.woorea.openstack.quantum.model.Port();
    try {
        Quantum client = quantumConnector.getClient();
        port.setNetworkId(subnet.getNetwork());
        // List<com.woorea.openstack.quantum.model.Port.Ip> ips = new ArrayList<>();
        // com.woorea.openstack.quantum.model.Port.Ip ip = new com.woorea.openstack.quantum.model.Port.Ip();
        // ip.setSubnetId(subnet.getId());
        // ips.add(ip);
        // port.setList(ips);
        port = client.ports().create(port).execute();
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return new OpenStackPort(context, port);
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Quantum(com.woorea.openstack.quantum.Quantum) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort)

Aggregations

Port (com.att.cdp.zones.model.Port)16 Context (com.att.cdp.zones.Context)12 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)8 NetworkService (com.att.cdp.zones.NetworkService)8 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 Server (com.att.cdp.zones.model.Server)6 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)6 Subnet (com.att.cdp.zones.model.Subnet)5 ArrayList (java.util.ArrayList)5 ZoneException (com.att.cdp.exceptions.ZoneException)4 OpenStackContext (com.att.cdp.openstack.OpenStackContext)4 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)4 ComputeService (com.att.cdp.zones.ComputeService)4 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)4 InterfaceAttachment (com.woorea.openstack.nova.model.InterfaceAttachment)3 InterfaceAttachments (com.woorea.openstack.nova.model.InterfaceAttachments)3 OpenStackACL (com.att.cdp.openstack.model.OpenStackACL)2 OpenStackFault (com.att.cdp.openstack.model.OpenStackFault)2 ACL (com.att.cdp.zones.model.ACL)2