Search in sources :

Example 11 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class TestNetworkService method createSubnetWithoutGateway.

/**
 * Verifies that we can create a subnet with no gateway IP address on a provider
 *
 * @throws ZoneException
 *             If the connection fails, user is not authorized, or the provider cannot perform the operation.
 */
@Test
@Ignore
public void createSubnetWithoutGateway() throws ZoneException {
    Context context = connect();
    NetworkService service = context.getNetworkService();
    try {
        // verify test network exists
        verifyTestNetworkHelper();
        List<Network> networks = service.getNetworksByName("CDP_Test_Network");
        assertNotNull(networks);
        assertFalse(networks.isEmpty());
        Network testNetwork = networks.get(0);
        // create the subnet
        Subnet subnetWithoutGateway = new Subnet();
        subnetWithoutGateway.setName("CDP_Test_IPV4_Subnet_Without_Gateway");
        subnetWithoutGateway.setNetwork(testNetwork.getId());
        subnetWithoutGateway.setIpv4(true);
        subnetWithoutGateway.setRouting("10.10.20.0/24");
        subnetWithoutGateway.setGatewayIp(null);
        service.createSubnet(subnetWithoutGateway);
        List<Subnet> subnets = service.getSubnetsByName("CDP_Test_IPV4_Subnet_Without_Gateway");
        assertFalse(subnets.isEmpty());
        for (Subnet subnet : subnets) {
            assertTrue(subnet.getRouting().equalsIgnoreCase("10.10.20.0/24"));
            assertTrue(subnet.getGatewayIp() == null);
        }
    } catch (ZoneException ze) {
        ze.printStackTrace();
        fail("Failed to create the test subnet without gateway IP");
    }
}
Also used : Context(com.att.cdp.zones.Context) ZoneException(com.att.cdp.exceptions.ZoneException) Network(com.att.cdp.zones.model.Network) NetworkService(com.att.cdp.zones.NetworkService) Subnet(com.att.cdp.zones.model.Subnet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class TestNetworkService method createSubnetWithDNSNameServers.

/**
 * Verifies that we can create a subnet with a specified set of DNS name servers on a provider
 *
 * @throws ZoneException
 *             If the connection fails, user is not authorized, or the provider cannot perform the operation.
 */
@Test
@Ignore
public void createSubnetWithDNSNameServers() throws ZoneException {
    Context context = connect();
    NetworkService service = context.getNetworkService();
    try {
        // verify test network exists
        verifyTestNetworkHelper();
        List<Network> networks = service.getNetworksByName("CDP_Test_Network");
        assertNotNull(networks);
        assertFalse(networks.isEmpty());
        Network testNetwork = networks.get(0);
        Subnet subnetWithGateway = new Subnet();
        subnetWithGateway.setName("CDP_Test_IPV4_Subnet_With_DNS_Name_Servers");
        subnetWithGateway.setNetwork(testNetwork.getId());
        subnetWithGateway.setIpv4(true);
        subnetWithGateway.setRouting("10.10.50.0/24");
        subnetWithGateway.setGatewayIp("10.10.50.1");
        ArrayList<String> dnsNames = new ArrayList<String>();
        dnsNames.add("0.0.0.5");
        dnsNames.add("0.0.0.7");
        subnetWithGateway.setDns(dnsNames);
        service.createSubnet(subnetWithGateway);
        List<Subnet> subnets = service.getSubnetsByName("CDP_Test_IPV4_Subnet_With_DNS_Name_Servers");
        assertFalse(subnets.isEmpty());
        for (Subnet subnet : subnets) {
            assertTrue(subnet.getRouting().equalsIgnoreCase("10.10.50.0/24"));
            assertTrue(subnet.getGatewayIp().equalsIgnoreCase("10.10.50.1"));
            assertTrue(subnet.getDns().contains("0.0.0.5"));
            assertTrue(subnet.getDns().contains("0.0.0.7"));
        }
    } catch (ZoneException ze) {
        ze.printStackTrace();
        fail("Failed to create the ipv4 test subnet with DNS name servers");
    }
}
Also used : Context(com.att.cdp.zones.Context) ZoneException(com.att.cdp.exceptions.ZoneException) Network(com.att.cdp.zones.model.Network) ArrayList(java.util.ArrayList) NetworkService(com.att.cdp.zones.NetworkService) Subnet(com.att.cdp.zones.model.Subnet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class TestNetworkService method createIPV6SubnetWithGateway.

/**
 * Verifies that we can create a subnet with a specified gateway IP address on a provider
 *
 * @throws ZoneException
 *             If the connection fails, user is not authorized, or the provider cannot perform the operation.
 */
@Test
@Ignore
public void createIPV6SubnetWithGateway() throws ZoneException {
    Context context = connect();
    NetworkService service = context.getNetworkService();
    try {
        // verify test network exists
        verifyTestNetworkHelper();
        List<Network> networks = service.getNetworksByName("CDP_Test_Network");
        assertNotNull(networks);
        assertFalse(networks.isEmpty());
        Network testNetwork = networks.get(0);
        Subnet ipv6SubnetWithGateway = new Subnet();
        ipv6SubnetWithGateway.setName("CDP_Test_IPV6_Subnet_With_Gateway");
        ipv6SubnetWithGateway.setNetwork(testNetwork.getId());
        ipv6SubnetWithGateway.setIpv4(false);
        ipv6SubnetWithGateway.setRouting("2001:db8:1234::/48");
        ipv6SubnetWithGateway.setGatewayIp("2001:db8:1234::1");
        service.createSubnet(ipv6SubnetWithGateway);
        List<Subnet> subnets = service.getSubnetsByName("CDP_Test_IPV6_Subnet_With_Gateway");
        assertFalse(subnets.isEmpty());
        for (Subnet subnet : subnets) {
            assertTrue(subnet.getRouting().equalsIgnoreCase("2001:db8:1234::/48"));
            assertTrue(subnet.getGatewayIp().equalsIgnoreCase("2001:db8:1234::1"));
        }
    } catch (ZoneException ze) {
        ze.printStackTrace();
        fail("Failed to create the ipv6 test subnet with gateway IP");
    }
}
Also used : Context(com.att.cdp.zones.Context) ZoneException(com.att.cdp.exceptions.ZoneException) Network(com.att.cdp.zones.model.Network) NetworkService(com.att.cdp.zones.NetworkService) Subnet(com.att.cdp.zones.model.Subnet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class AbstractOpenStackIdentityService method getKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#getKeyPair(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public KeyPair getKeyPair(String name) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, name);
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        KeyPairs pairs;
        try {
            pairs = connector.getClient().keyPairs().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get key-pair " + name), e);
        }
        if (pairs == null || pairs.getList() == null) {
            return null;
        }
        for (com.woorea.openstack.nova.model.KeyPair pair : pairs.getList()) {
            if (pair.getName().equals(name)) {
                return new OpenStackKeyPair(context, pair);
            }
        }
        return null;
    }
    throw new ZoneException("Unable to retrieve key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) KeyPairs(com.woorea.openstack.nova.model.KeyPairs) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 15 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class AbstractOpenStackIdentityService method getTenants.

public Set<Tenant> getTenants() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Set<Tenant> tenants = new HashSet<Tenant>();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    try {
        Tenants tenantList = keystone.tenants().list().execute();
        for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
            tenants.add(new OpenStackTenant((OpenStackContext) context, t));
        }
    } catch (OpenStackConnectException e) {
        throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
    } catch (OpenStackResponseException e) {
        throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
    }
    return tenants;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Tenant(com.att.cdp.zones.model.Tenant) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) HashSet(java.util.HashSet)

Aggregations

ZoneException (com.att.cdp.exceptions.ZoneException)40 Context (com.att.cdp.zones.Context)30 OpenStackContext (com.att.cdp.openstack.OpenStackContext)18 NetworkService (com.att.cdp.zones.NetworkService)15 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)15 Test (org.junit.Test)15 Network (com.att.cdp.zones.model.Network)13 Ignore (org.junit.Ignore)13 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)11 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)11 Server (com.att.cdp.zones.model.Server)9 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)8 Subnet (com.att.cdp.zones.model.Subnet)8 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)8 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 InvalidRequestException (com.att.cdp.exceptions.InvalidRequestException)5 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)5 ContextClosedException (com.att.cdp.exceptions.ContextClosedException)4