Package com.cloud.bridge.service.core.ec2

Examples of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup


    }

    private void authorizeSecurityGroupIngress( HttpServletRequest request, HttpServletResponse response )
            throws ADBException, XMLStreamException, IOException {
        // -> parse the complicated paramters into our standard object
        EC2AuthorizeRevokeSecurityGroup EC2request = new EC2AuthorizeRevokeSecurityGroup();

        String[] groupName = request.getParameterValues( "GroupName" );
        if ( null != groupName && 0 < groupName.length )
            EC2request.setName( groupName[0] );
        else { response.sendError(530, "Missing GroupName parameter" ); return; }

        // -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
        int nCount = 1;
        do
        {    EC2IpPermission perm = new EC2IpPermission();        

        String[] protocol = request.getParameterValues( "IpPermissions." + nCount + ".IpProtocol" );
        if ( null != protocol && 0 < protocol.length )
            perm.setProtocol( protocol[0] );
        else break;

        String[] fromPort = request.getParameterValues( "IpPermissions." + nCount + ".FromPort" );
            if ( null != fromPort && 0 < fromPort.length ) {
                if ( protocol[0].equalsIgnoreCase("icmp") )
                    perm.setIcmpType( fromPort[0] ) ;
                else
                    perm.setFromPort( Integer.parseInt( fromPort[0]) );
            }

        String[] toPort = request.getParameterValues( "IpPermissions." + nCount + ".ToPort" );
            if ( null != toPort && 0 < toPort.length ) {
                if ( protocol[0].equalsIgnoreCase("icmp") )
                    perm.setIcmpCode( toPort[0] );
                else
                    perm.setToPort( Integer.parseInt( toPort[0]) );
            }

        // -> list: IpPermissions.n.IpRanges.m.CidrIp
        int mCount = 1;
        do
        String[] ranges = request.getParameterValues( "IpPermissions." + nCount + ".IpRanges." + mCount + ".CidrIp" );
        if ( null != ranges && 0 < ranges.length)
            perm.addIpRange( ranges[0] );
        else break;
        mCount++;

        } while( true );

        // -> list: IpPermissions.n.Groups.m.UserId and IpPermissions.n.Groups.m.GroupName
        mCount = 1;
        do
        String[] user = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".UserId" );
        if ( null == user || 0 == user.length) break;

        String[] name = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".GroupName" );
        if ( null == name || 0 == name.length) break;

        EC2SecurityGroup group = new EC2SecurityGroup();
        group.setAccount( user[0] );
        group.setName( name[0] );
        perm.addUser( group );
        mCount++;

        } while( true );

        // -> multiple IP permissions can be specified per group name
        EC2request.addIpPermission( perm )
        nCount++;

        } while( true );

        if (1 == nCount) { response.sendError(530, "At least one IpPermissions required" ); return; }
View Full Code Here


        }
        return request;
    }

    private EC2AvailabilityZonesFilterSet toAvailabiltyZonesFilterSet( FilterSetType fst )  {
        EC2AvailabilityZonesFilterSet azfs = new EC2AvailabilityZonesFilterSet();

        FilterType[] items = fst.getItem();
        if (items != null) {
            for (FilterType item : items) {
                EC2Filter oneFilter = new EC2Filter();
                String filterName = item.getName();
                oneFilter.setName( filterName );

                ValueSetType vft = item.getValueSet();
                ValueType[] valueItems = vft.getItem();
                for (ValueType valueItem : valueItems) {
                    oneFilter.addValueEncoded( valueItem.getValue());
                }
                azfs.addFilter( oneFilter );
            }
        }
        return azfs;
    }
View Full Code Here

        }   

        // add filters
        EC2Filter[] filterSet = extractFilters( request );
        if ( filterSet != null ) {
            EC2AvailabilityZonesFilterSet afs = new EC2AvailabilityZonesFilterSet();
            for( int i=0; i < filterSet.length; i++ ) {
                afs.addFilter(filterSet[i]);
            }
            EC2request.setFilterSet( afs );
        }

        // -> execute the request
View Full Code Here

        }
        return request;
    }

  public CreateImageResponse createImage(CreateImage createImage) {
    EC2CreateImage request = new EC2CreateImage();
    CreateImageType cit = createImage.getCreateImage();
   
    request.setInstanceId( cit.getInstanceId());
    request.setName( cit.getName());
    request.setDescription( cit.getDescription());
    return toCreateImageResponse( engine.createImage(request));
  }
View Full Code Here

        serializeResponse(response, EC2response);
    }

    private void createImage( HttpServletRequest request, HttpServletResponse response )
            throws ADBException, XMLStreamException, IOException {
        EC2CreateImage EC2request = new EC2CreateImage();

        String[] instanceId = request.getParameterValues( "InstanceId" );
        if ( null != instanceId && 0 < instanceId.length )
            EC2request.setInstanceId( instanceId[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
        }

        String[] name = request.getParameterValues( "Name" );
        if ( null != name && 0 < name.length )
            EC2request.setName( name[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Name");
        }

        String[] description = request.getParameterValues( "Description" );
        if ( null != description && 0 < description.length ) {
            if (description[0].length() > 255)
                throw new EC2ServiceException( ClientError.InvalidParameterValue,
                        "Length of the value of parameter Description should be less than 255");
            EC2request.setDescription( description[0] );
        }


        // -> execute the request
        CreateImageResponse EC2response = EC2SoapServiceImpl.toCreateImageResponse( ServiceProvider.getInstance().getEC2Engine().createImage( EC2request ));
View Full Code Here

   
    return response;
  }
 
  public CreateKeyPairResponse createKeyPair(CreateKeyPair createKeyPair) {
    EC2CreateKeyPair ec2Request = new EC2CreateKeyPair();
      if (ec2Request != null) {
        ec2Request.setKeyName(createKeyPair.getCreateKeyPair().getKeyName());
      }

    return toCreateKeyPair(engine.createKeyPair( ec2Request ));
  }
View Full Code Here

    CreateSnapshotType cst = createSnapshot.getCreateSnapshot();
    return toCreateSnapshotResponse( engine.createSnapshot( cst.getVolumeId()), engine);
  }

  public CreateVolumeResponse createVolume(CreateVolume createVolume) {
    EC2CreateVolume request = new EC2CreateVolume();
    CreateVolumeType cvt = createVolume.getCreateVolume();
   
    request.setSize( cvt.getSize());
    request.setSnapshotId(cvt.getSnapshotId() != null ? cvt.getSnapshotId() : null);
    request.setZoneName( cvt.getAvailabilityZone());
    return toCreateVolumeResponse( engine.createVolume( request ));
  }
View Full Code Here

   
    return response;
  }
 
  public DeleteKeyPairResponse deleteKeyPair(DeleteKeyPair deleteKeyPair) {
    EC2DeleteKeyPair ec2Request = new EC2DeleteKeyPair();
    ec2Request.setKeyName(deleteKeyPair.getDeleteKeyPair().getKeyName());
   
    return toDeleteKeyPair(engine.deleteKeyPair(ec2Request));
  }
View Full Code Here

  }

 
    @Override
    public DescribeAddressesResponse describeAddresses(DescribeAddresses describeAddresses) {
        EC2DescribeAddresses ec2Request = new EC2DescribeAddresses();
        DescribeAddressesType dat = describeAddresses.getDescribeAddresses();
       
        DescribeAddressesInfoType dait = dat.getPublicIpsSet();
        DescribeAddressesItemType[] items = dait.getItem();
        if (items != null) {  // -> can be empty
          for (DescribeAddressesItemType itemType : items)
            ec2Request.addPublicIp( itemType.getPublicIp());
        }

        FilterSetType fset = dat.getFilterSet();
        if (fset != null) {
          ec2Request.setFilterSet(toAddressFilterSet(fset));
        }
       
        return toDescribeAddressesResponse( engine.describeAddresses( ec2Request ));
    }
View Full Code Here

    image.setId( dit.getImageId());
    return toDeregisterImageResponse( engine.deregisterImage( image ));
  }

  public DescribeAvailabilityZonesResponse describeAvailabilityZones(DescribeAvailabilityZones describeAvailabilityZones) {
    EC2DescribeAvailabilityZones request = new EC2DescribeAvailabilityZones();
   
    DescribeAvailabilityZonesType dazt = describeAvailabilityZones.getDescribeAvailabilityZones();
    DescribeAvailabilityZonesSetType dazs = dazt.getAvailabilityZoneSet();
    DescribeAvailabilityZonesSetItemType[] items = dazs.getItem();
    if (null != items) {  // -> can be empty
      for( int i=0; i < items.length; i++ ) request.addZone( items[i].getZoneName());
    }

        FilterSetType fst = dazt.getFilterSet();
        if (fst != null) {
            request.setFilterSet( toAvailabiltyZonesFilterSet(fst));
        }

    return toDescribeAvailabilityZonesResponse( engine.describeAvailabilityZones( request ));
  }
View Full Code Here

TOP

Related Classes of com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.