Search in sources :

Example 76 with Context

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

the class OpenStackSnapshotService method getSnapshots.

/**
 * Returns a list of snapshots that match the supplied name
 *
 * @param name
 *            The name pattern of the snapshots to be located. The name is a regular expression that is suitable for
 *            use in the Java String.matches() method.
 * @return A list (potentially empty) of all snapshots that match the specified name pattern
 * @throws ZoneException
 *             - If the snapshot service cannot be accessed.
 * @see java.lang.String#matches(String)
 * @see com.att.cdp.zones.SnapshotService#getSnapshots(java.lang.String)
 */
@Override
public List<Snapshot> getSnapshots(String name) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, name);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Snapshot> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Snapshots snapshots = nova.getClient().snapshots().list(true).execute();
        for (com.woorea.openstack.nova.model.Snapshot snap : snapshots) {
            if (name != null) {
                if (snap.getName() != null && snap.getName().matches(name)) {
                    list.add(new OpenStackSnapshot(context, snap));
                }
            } else {
                list.add(new OpenStackSnapshot(context, snap));
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) Snapshot(com.att.cdp.zones.model.Snapshot) AbstractSnapshot(com.att.cdp.zones.spi.AbstractSnapshot) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 77 with Context

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

the class OpenStackSnapshotService method connect.

/**
 * This is a helper method used to construct the Nova service object and setup the environment to access the
 * OpenStack compute service (Nova).
 *
 * @throws NotLoggedInException
 *             If the user is not logged in
 * @throws ContextClosedException
 *             If the user attempts an operation after the context is closed
 */
private void connect() throws NotLoggedInException, ContextClosedException {
    checkLogin();
    checkOpen();
    Context context = getContext();
    OpenStackContext osContext = (OpenStackContext) context;
    nova = osContext.getNovaConnector();
    ((OpenStackContext) context).refreshIfStale(nova);
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext)

Example 78 with Context

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

the class OpenStackStackService method getStack.

/**
 * @see com.att.cdp.zones.StackService#getStack(java.lang.String, java.lang.String)
 */
@Override
public Stack getStack(String name, String id) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Orchestration");
    RequestState.put(RequestState.SERVICE_URL, connector.getEndpoint());
    Heat heat = connector.getClient();
    OpenStackStack stack = null;
    try {
        com.woorea.openstack.heat.model.Stack osStack = heat.getStacks().get(name, id).execute();
        stack = new OpenStackStack(context, osStack);
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return stack;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackStack(com.att.cdp.openstack.model.OpenStackStack) Heat(com.woorea.openstack.heat.Heat) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 79 with Context

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

the class OpenStackNetworkService method deleteLoadBalancerMember.

/**
 * @see com.att.cdp.zones.NetworkService#deleteLoadBalancerMember(com.att.cdp.zones.model.LoadBalancerMember)
 */
@SuppressWarnings("nls")
@Override
public void deleteLoadBalancerMember(LoadBalancerMember loadBalancerMember) throws ZoneException {
    checkArg(loadBalancerMember, "loadBalancerMember");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.LOADBALANCERMEMBER, loadBalancerMember.getId());
    RequestState.put(RequestState.SERVICE, "Network");
    RequestState.put(RequestState.SERVICE_URL, quantumConnector.getEndpoint());
    try {
        Quantum client = quantumConnector.getClient();
        client.lbaas().Member().delete(loadBalancerMember.getId()).execute();
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Quantum(com.woorea.openstack.quantum.Quantum) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 80 with Context

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

the class OpenStackNetworkService method assignIpAddressFromPool.

/**
 * @see com.att.cdp.zones.NetworkService#assignIpAddressFromPool(java.lang.String, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public String assignIpAddressFromPool(String serverId, String pool) throws ZoneException {
    checkArg(serverId, "serverId");
    checkArg(pool, "pool");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVER, serverId);
    RequestState.put(RequestState.POOL, pool);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, novaConnector.getEndpoint());
    Nova client = novaConnector.getClient();
    FloatingIpsExtension extension = client.floatingIps();
    if (extension == null) {
        throw new NotSupportedException(EELFResourceManager.format(OSMsg.PAL_OS_UNSUPPORTED_OPERATION, "getAvailableAddresses", context.getProvider().getName()));
    }
    try {
        String ip = reserveFreeFloatingIPAddress(pool);
        if (ip != null) {
            assignIpAddress(serverId, ip);
            return ip;
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    throw new NotSupportedException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_UNAVAILABLE, "Floating IP Address", context.getProvider().getName()));
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) FloatingIpsExtension(com.woorea.openstack.nova.api.extensions.FloatingIpsExtension) Nova(com.woorea.openstack.nova.Nova) NotSupportedException(com.att.cdp.exceptions.NotSupportedException)

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