Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2014 Dell, Inc ==================================================================== Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ====================================================================
 
 
 package org.dasein.cloud.azure.network;
 
 
 import  javax.annotation.Nonnull;
 import  javax.annotation.Nullable;
Created by Vlad_Munthiu on 7/31/2014.
 
     static private final Logger logger = Logger.getLogger(AzureIpAddressSupport.class);
     static private final Logger wire   = Azure.getWireLogger(AzureIpAddressSupport.class);
 
     private Azure provider;
 
     public static final String RESOURCE_ROLE = "/services/hostedservices/%s/deployments/%s/roles/%s";
 
     public AzureIpAddressSupport(Azure provider)
     {
         super(provider);
         this. = provider;
     }
    
Assigns the specified address to the target server. This method should be called only if isAssigned(AddressType) for the specified address's address type is true. If it is not, you will see the RuntimeException org.dasein.cloud.OperationNotSupportedException thrown.

Parameters:
addressId the unique identifier of the address to be assigned
serverId the unique ID of the server to which the address is being assigned
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address assignment of the specified address type
 
     @Override
     public void assign(@Nonnull String addressId, @Nonnull String serverIdthrows InternalExceptionCloudException {
         throw new OperationNotSupportedException("AzureIpAddressSupport#assign not supported");
     }

    
Assigns the specified address to the specified network interface.

Parameters:
addressId the unique ID of the IP address to assign
nicId the unique ID of the network interface to which the address is being assigned
Throws:
org.dasein.cloud.InternalException an error occurred locally while performing the assignment
org.dasein.cloud.CloudException an error occurred in the cloud provider while performing the assignment
 
     @Override
     public void assignToNetworkInterface(@Nonnull String addressId, @Nonnull String nicIdthrows InternalExceptionCloudException {
         throw new OperationNotSupportedException("AzureIpAddressSupport#assignToNetworkInterface not supported");
     }

    
Forwards the specified public IP address traffic on the specified public port over to the specified private port on the specified server. If the server goes away, you will generally still have traffic being forwarded to the private IP formally associated with the server, so it is best to stop forwarding before terminating a server.

You should check isForwarding() before calling this method. The implementation should throw a org.dasein.cloud.OperationNotSupportedException RuntimeException if the underlying cloud does not support IP address forwarding.

Parameters:
addressId the unique ID of the public IP address to be forwarded
publicPort the public port of traffic to be forwarded
protocol the network protocol being forwarded (not all clouds support ICMP)
privatePort the private port on the server to which traffic should be forwarded
onServerId the unique ID of the server to which traffic is to be forwarded
Returns:
the rule ID for the forwarding rule that is created
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address forwarding
    @Nonnull
    @Override
    public String forward(@Nonnull String addressIdint publicPort, @Nonnull Protocol protocolint privatePort, @Nonnull String onServerIdthrows InternalExceptionCloudException {
        PersistentVMRoleModel persistentVMRoleModel = getVMRole(onServerId);
        if(persistentVMRoleModel == null)
            throw new InternalException("Cannot find Azure virtual machine with id: " + onServerId);
        inputEndpoint.setLocalPort(String.valueOf(privatePort));
        inputEndpoint.setPort(String.valueOf(publicPort));
        inputEndpoint.setProtocol(protocol.toString());
        inputEndpoint.setName(protocol.toString() + String.valueOf(publicPort));
        if(persistentVMRoleModel.getConfigurationSets().get(0).getInputEndpoints() == null)
            persistentVMRoleModel.getConfigurationSets().get(0).setInputEndpoints(new ArrayList<PersistentVMRoleModel.InputEndpoint>());
        persistentVMRoleModel.getConfigurationSets().get(0).getInputEndpoints().add(inputEndpoint);
        updateVMRole(onServerIdpersistentVMRoleModel);
        return inputEndpoint.getName();
    }

    
Provides access to meta-data about IP Address capabilities in the current region of this cloud.

Returns:
a description of the features supported by this region of this cloud
Throws:
org.dasein.cloud.InternalException an error occurred within the Dasein Cloud API implementation
org.dasein.cloud.CloudException an error occurred within the cloud provider
    @Nonnull
    @Override
        return new AzureIpAddressCapabilities(this.);
    }

    
Provides the org.dasein.cloud.network.IpAddress identified by the specified unique address ID.

Parameters:
addressId the unique ID of the IP address being requested
Returns:
the matching org.dasein.cloud.network.IpAddress
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
    @Nullable
    @Override
    public IpAddress getIpAddress(@Nonnull String addressIdthrows InternalExceptionCloudException {
        throw new OperationNotSupportedException("AzureIpAddressSupport#getIpAddress not supported");
    }

    
The cloud provider-specific term for an IP address. It's hard to fathom what other than "IP address" anyone could use.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.getProviderTermForIpAddress(java.util.Locale)
Parameters:
locale the locale into which the term should be translated
Returns:
the cloud provider-specific term for an IP address
    @Nonnull
    @Override
    public String getProviderTermForIpAddress(@Nonnull Locale locale) {
        return "";
    }

    
Indicates whether you need to specify which VLAN you are tying a static IP address to when creating an IP address for use in a VLAN. REQUIRED means you must specify the VLAN, OPTIONAL means you may, and NONE means you do not specify a VLAN.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.identifyVlanForVlanIPRequirement()
Returns:
the level of requirement for specifying a VLAN when creating a VLAN IP address
Throws:
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
    @Nonnull
    @Override
        throw new OperationNotSupportedException("AzureIpAddressSupport#identifyVlanForVlanIPRequirement not supported");
    }

    
Indicates whether the underlying cloud supports the assignment of addresses of the specified type.

Deprecated:
use isAssigned(org.dasein.cloud.network.IPVersion)
Parameters:
type the type of address being checked (public or private)
Returns:
true if addresses of the specified type are assignable to servers
    @Override
    public boolean isAssigned(@Nonnull AddressType type) {
        return false;
    }

    
Indicates whether the underlying cloud supports the assignment of addresses of the specified version

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.isAssigned(org.dasein.cloud.network.IPVersion)
Parameters:
version the IP version being checked
Returns:
true if the addresses of the specified version are assignable to cloud resources for public routing
Throws:
org.dasein.cloud.CloudException an error occurred with the cloud provider determining support
org.dasein.cloud.InternalException a local error occurred determining support
    @Override
    public boolean isAssigned(@Nonnull IPVersion versionthrows CloudExceptionInternalException {
        return false;
    }

    
When addresses are assignable, they may be assigned at launch, post-launch, or both. org.dasein.cloud.compute.VirtualMachineCapabilities.identifyStaticIPRequirement() will tell you what must be done at launch time. This method indicates whether or not assignable IPs may be assigned after launch. This method should never return true when isAssigned(org.dasein.cloud.network.IPVersion) returns false.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.isAssignablePostLaunch(org.dasein.cloud.network.IPVersion)
Parameters:
version the IP version being checked
Returns:
true if IP addresses of the specified version can be assigned post launch
Throws:
org.dasein.cloud.CloudException an error occurred with the cloud provider determining support
org.dasein.cloud.InternalException a local error occurred determining support
    @Override
    public boolean isAssignablePostLaunch(@Nonnull IPVersion versionthrows CloudExceptionInternalException {
        return false;
    }

    
Indicates whether the underlying cloud supports the forwarding individual port traffic on public IP addresses to hosts private IPs. These addresses may also be used for load balancers in some clouds as well.

Deprecated:
use isForwarding(org.dasein.cloud.network.IPVersion)
Returns:
true if public IPs may be forwarded on to private IPs
    @Override
    public boolean isForwarding() {
        return true;
    }

    
Indicates whether the underlying cloud supports the forwarding of traffic on individual ports targeted to addresses of the specified version on to resources in the cloud.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.isForwarding(org.dasein.cloud.network.IPVersion)
Parameters:
version the IP version being checked
Returns:
true if forwarding is supported
Throws:
org.dasein.cloud.CloudException an error occurred with the cloud provider determining support
org.dasein.cloud.InternalException a local error occurred determining support
    @Override
    public boolean isForwarding(IPVersion versionthrows CloudExceptionInternalException {
        return true;
    }

    
Indicates whether the underlying cloud allows you to make programmatic requests for new IP addresses of the specified type

Deprecated:
use isRequestable(org.dasein.cloud.network.IPVersion)
Parameters:
type the type of address being checked (public or private)
Returns:
true if there are programmatic mechanisms for allocating new IPs of the specified type
    @Override
    public boolean isRequestable(@Nonnull AddressType type) {
        return false;
    }

    
Indicates whether or not you can request static IP addresses of the specified Internet Protocol version.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.isRequestable(org.dasein.cloud.network.IPVersion)
Parameters:
version the IP version you may want to request
Returns:
true if you can make requests from the cloud provider to add addresses of this version to your pool
Throws:
org.dasein.cloud.CloudException an error occurred with the cloud provider while determining if your account has support
org.dasein.cloud.InternalException a local exception occurred while determining support
    @Override
    public boolean isRequestable(@Nonnull IPVersion versionthrows CloudExceptionInternalException {
        return false;
    }

    
Indicates whether this account is subscribed to leverage IP address services in the target cloud.

Returns:
true if the account holder is subscribed
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
    @Override
    public boolean isSubscribed() throws CloudExceptionInternalException {
        return false;
    }

    
Lists all (or unassigned) private IP addresses from the account holder's private IP address pool. This method is safe to call even if private IP forwarding is not supported. It will simply return java.util.Collections.emptyList().

Deprecated:
private IP pools no longer make sense, use the org.dasein.cloud.network.VLANSupport class
Parameters:
unassignedOnly indicates that only unassigned addresses are being sought
Returns:
all private IP addresses or the unassigned ones from the pool
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
OperationNotSupportedException the requested version is not supported
    @Nonnull
    @Override
    public Iterable<IpAddresslistPrivateIpPool(boolean unassignedOnlythrows InternalExceptionCloudException {
        return Collections.emptyList();
    }

    
Lists all (or unassigned) public IP addresses from the account holder's public IP address pool. This method is safe to call even if public IP forwarding is not supported. It will simply return java.util.Collections.emptyList().

Deprecated:
use listIpPool(org.dasein.cloud.network.IPVersion, boolean)
Parameters:
unassignedOnly indicates that only unassigned addresses are being sought
Returns:
all public IP addresses or the unassigned ones from the pool
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
OperationNotSupportedException the requested version is not supported
    @Nonnull
    @Override
    public Iterable<IpAddresslistPublicIpPool(boolean unassignedOnlythrows InternalExceptionCloudException {
        return Collections.emptyList();
    }

    
Lists all IP addresses of the specified IP version that are allocated to the account holder's IP address pool. If the specified version is not supported, an empty list should be returned.

Parameters:
version the version of the IP protocol for which you are looking for IP addresses
unassignedOnly show only IP addresses that have yet to be assigned to cloud resources
Returns:
all matching IP addresses from the IP address pool
Throws:
org.dasein.cloud.InternalException a local error occurred loading the IP addresses
org.dasein.cloud.CloudException an error occurred with the cloud provider while requesting the IP addresses
    @Nonnull
    @Override
    public Iterable<IpAddresslistIpPool(@Nonnull IPVersion versionboolean unassignedOnlythrows InternalExceptionCloudException {
        return Collections.emptyList();
    }

    
Lists all IP addresses of the specified IP version that are allocated to the account holder's IP address pool. If the specified version is not supported, an empty list should be returned. This method implements a callable so it can be called concurrently.

Parameters:
version the version of the IP protocol for which you are looking for IP addresses
unassignedOnly show only IP addresses that have yet to be assigned to cloud resources
Returns:
all matching IP addresses from the IP address pool
Throws:
org.dasein.cloud.InternalException a local error occurred loading the IP addresses
org.dasein.cloud.CloudException an error occurred with the cloud provider while requesting the IP addresses
    @Nonnull
    @Override
    public Future<Iterable<IpAddress>> listIpPoolConcurrently(@Nonnull IPVersion versionboolean unassignedOnlythrows InternalExceptionCloudException {
        return null;
    }

    
Lists the status of all IP addresses of the specified IP version that are allocated to the account holder's IP address pool. If the specified version is not supported, an empty list should be returned.

Parameters:
version the version of the IP protocol for which you are looking for IP addresses
Returns:
the status of all matching IP addresses from the IP address pool
Throws:
org.dasein.cloud.InternalException a local error occurred loading the IP addresses
org.dasein.cloud.CloudException an error occurred with the cloud provider while requesting the IP addresses
    @Nonnull
    @Override
    public Iterable<ResourceStatuslistIpPoolStatus(@Nonnull IPVersion versionthrows InternalExceptionCloudException {
        return Collections.emptyList();
    }

    
Lists the IP forwarding rules associated with the specified public IP address. This method is safe to call even when requested on a private IP address or when IP forwarding is not supported. In those situations, java.util.Collections.emptyList() will be returned.

Parameters:
serverId the unique ID of the virtual machine whose forwarding rules will be sought
Returns:
all IP forwarding rules for the specified IP address
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
    @Override
    public @Nonnull Iterable<IpForwardingRulelistRulesForServer(@Nonnull String serverIdthrows InternalExceptionCloudException {
        PersistentVMRoleModel persistentVMRoleModel = getVMRole(serverId);
        if(persistentVMRoleModel == null)
            throw new InternalException("Cannot find Azure virtual machine with id: " + serverId);
        ArrayList<IpForwardingRulerules = new ArrayList<IpForwardingRule>();
        if(persistentVMRoleModel.getConfigurationSets().get(0).getInputEndpoints() != null)
        {
            for (PersistentVMRoleModel.InputEndpoint endpoint : persistentVMRoleModel.getConfigurationSets().get(0).getInputEndpoints())
            {
                IpForwardingRule rule = new IpForwardingRule();
                rule.setProviderRuleId(endpoint.getName());
                rule.setPublicPort(Integer.parseInt(endpoint.getPort()));
                rule.setPrivatePort(Integer.parseInt(endpoint.getLocalPort()));
                rule.setServerId(serverId);
                rules.add(rule);
            }
        }
        return rules;
    }

    
Lists all IP protocol versions supported for static IP addresses in this cloud.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.listSupportedIPVersions()
Returns:
a list of supported versions
Throws:
org.dasein.cloud.CloudException an error occurred checking support for IP versions with the cloud provider
org.dasein.cloud.InternalException a local error occurred preparing the supported version
    @Nonnull
    @Override
        return Collections.emptyList();
    }

    
When a cloud allows for programmatic requesting of new IP addresses, you may also programmaticall release them (isRequestable(org.dasein.cloud.network.AddressType)). This method will release the specified IP address from your pool and you will no longer be able to use it for assignment or forwarding.

Parameters:
addressId the unique ID of the address to be release
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address requests
    @Override
    public void releaseFromPool(@Nonnull String addressIdthrows InternalExceptionCloudException {
        throw new OperationNotSupportedException("AzureIpAddressSupport#releaseFromPool not supported");
    }

    
Releases an IP address assigned to a server so that it is unassigned in the address pool. You should call this method only when isAssigned(org.dasein.cloud.network.AddressType) is true for addresses of the target address's type.

Parameters:
addressId the address ID to release from its server assignment
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address assignment for addresses of the specified type
    @Override
    public void releaseFromServer(@Nonnull String addressIdthrows InternalExceptionCloudException {
        throw new OperationNotSupportedException("AzureIpAddressSupport#releaseFromServer not supported");
    }

    
When requests for new IP addresses may be handled programmatically, this method allocates a new IP address of the specified type. You should call it only if isRequestable(org.dasein.cloud.network.AddressType) is true for the address's type.

Deprecated:
use request(org.dasein.cloud.network.IPVersion)
Parameters:
typeOfAddress the type of address being requested
Returns:
the newly allocated IP address
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address requests
    @Nonnull
    @Override
    public String request(@Nonnull AddressType typeOfAddressthrows InternalExceptionCloudException {
        return "";
    }

    
Requests an IP address of the specified version for the flat (non-VLAN) network space.

Parameters:
version the IP version of the address to be requested
Returns:
the unique ID of the newly provisioned static IP address
Throws:
org.dasein.cloud.InternalException a local error occurred while preparing the request
org.dasein.cloud.CloudException an error occurred with the cloud while provisioning the new address
    @Nonnull
    @Override
    public String request(@Nonnull IPVersion versionthrows InternalExceptionCloudException {
        return "";
    }

    
Requests a public IP address that may be used with a VLAN. This version may be used only when identifyVlanForVlanIPRequirement() is not org.dasein.cloud.Requirement.REQUIRED.

Parameters:
version the IP version of the address to be requested
Returns:
the unique ID of a newly provisioned public IP address
Throws:
org.dasein.cloud.InternalException an error occurred locally while attempting to provision the IP address
org.dasein.cloud.CloudException an error occurred in the cloud provider while provisioning the IP address
OperationNotSupportedException either VLAN IPs are not supported or they must be explicitly associated with a VLAN
    @Nonnull
    @Override
    public String requestForVLAN(@Nonnull IPVersion versionthrows InternalExceptionCloudException {
        return "";
    }

    
Requests a public IP address that must be used with a specific VLAN. This version may be used only when identifyVlanForVlanIPRequirement() is not org.dasein.cloud.Requirement.NONE.

Parameters:
version the IP version of the address to be requested
vlanId the unique ID of the VLAN to which the IP address will be assigned
Returns:
the unique ID of a newly provisioned public IP address
Throws:
org.dasein.cloud.InternalException an error occurred locally while attempting to provision the IP address
org.dasein.cloud.CloudException an error occurred in the cloud provider while provisioning the IP address
OperationNotSupportedException either VLAN IPs are not supported or they cannot be explicitly associated with a VLAN
    @Nonnull
    @Override
    public String requestForVLAN(@Nonnull IPVersion version, @Nonnull String vlanIdthrows InternalExceptionCloudException {
        return "";
    }

    
Removes the specified forwarding rule from the address with which it is associated.

Parameters:
ruleId the rule to be removed
Throws:
org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation
org.dasein.cloud.CloudException an error occurred processing the request in the cloud
org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address forwarding
    @Override
    public void stopForwardToServer(@Nonnull final String ruleId, @Nonnull String serverIdthrows InternalExceptionCloudException {
        PersistentVMRoleModel persistentVMRoleModel = getVMRole(serverId);
        if(persistentVMRoleModel == null)
            throw new InternalException("Cannot find Azure virtual machine with id: " + serverId);
        CollectionUtils.filter(persistentVMRoleModel.getConfigurationSets().get(0).getInputEndpoints(), new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                return ((PersistentVMRoleModel.InputEndpointobject).getName().equalsIgnoreCase(ruleId) == false;
            }
        });
        updateVMRole(serverIdpersistentVMRoleModel);
    }

    
Indicates whether or not IP addresses can be allocated for VLAN use. Only makes sense when the cloud actually supports VLANS.

Deprecated:
use org.dasein.cloud.network.IPAddressCapabilities.supportsVLANAddresses(org.dasein.cloud.network.IPVersion)
Parameters:
ofVersion the version of public IP address that might be routed to a VLAN resource
Returns:
true if an IP address may be allocated for use by VLANs
Throws:
org.dasein.cloud.InternalException a local error occurred determining support
org.dasein.cloud.CloudException an error occurred with the cloud provider in determining support
    @Override
    public boolean supportsVLANAddresses(@Nonnull IPVersion ofVersionthrows InternalExceptionCloudException {
        return false;
    }

    
Maps the specified Dasein Cloud service action to an identifier specific to an underlying cloud. If there is no mapping that makes any sense, the method will return an empty array.

Parameters:
action the Dasein Cloud service action
Returns:
a list of cloud-specific IDs (e.g. iam:ListGroups) representing an action with this cloud provider
    @Nonnull
    @Override
    public String[] mapServiceAction(@Nonnull ServiceAction action) {
        return new String[0];
    }
    private void updateVMRole(String vmIdPersistentVMRoleModel persistentVMRoleModelthrows CloudExceptionInternalException {
        AzureRoleDetails roleDetails = AzureRoleDetails.fromString(vmId);
        try {
            new AzureMethod(this.).put(String.format(roleDetails.getServiceName(), roleDetails.getDeploymentName(), roleDetails.getRoleName()), persistentVMRoleModel);
        } catch (JAXBException e) {
            .error(e.getMessage());
            throw new InternalException(e);
        }
    }
    private PersistentVMRoleModel getVMRole(String vmId)
    {
        AzureRoleDetails roleDetails = AzureRoleDetails.fromString(vmId);
        try {
            return new AzureMethod(this.).get(PersistentVMRoleModel.class, String.format(roleDetails.getServiceName(), roleDetails.getDeploymentName(), roleDetails.getRoleName()));
        } catch (Exception ex){
            return null;
        }
    }
New to GrepCode? Check out our FAQ X