Example #1
0
 def _associate_floatingip_to_port(self, context, floating_ip_address,
                                   port_id):
     port = self._core_plugin.get_port(context, port_id)
     ec2_id = None
     fixed_ip_address = None
     # TODO: Assuming that there is only one fixed IP
     if len(port['fixed_ips']) > 0:
         fixed_ip = port['fixed_ips'][0]
         if 'ip_address' in fixed_ip:
             fixed_ip_address = fixed_ip['ip_address']
             search_opts = {
                 'ip': fixed_ip_address,
                 'tenant_id': context.tenant_id
             }
             server_list = self.aws_utils.get_nova_client().servers.list(
                 search_opts=search_opts)
             if len(server_list) > 0:
                 server = server_list[0]
                 if 'ec2_id' in server.metadata:
                     ec2_id = server.metadata['ec2_id']
     if floating_ip_address is not None and ec2_id is not None:
         self.aws_utils.associate_elastic_ip_to_ec2_instance(
             floating_ip_address, ec2_id)
         LOG.info("EC2 ID found for IP %s : %s" %
                  (fixed_ip_address, ec2_id))
     else:
         LOG.warning("EC2 ID not found to associate the floating IP")
         raise exceptions.AwsException(
             error_code="No Server Found",
             message="No server found with the Required IP")
Example #2
0
def _process_exception(e, dry_run):
    if dry_run:
        error_code = e.response['Code']
        if not error_code == 'DryRunOperation':
            raise exceptions.AwsException(
                error_code='AuthFailure',
                message='Check your AWS authorization')
    else:
        if isinstance(e, botocore.exceptions.ClientError):
            error_code = e.response['Error']['Code']
            error_message = e.response['Error']['Message']
            raise exceptions.AwsException(error_code=error_code,
                                          message=error_message)
        else:
            # TODO: This might display all Exceptions to the user which
            # might be irrelevant, keeping it until it becomes stable
            error_message = e.message
            raise exceptions.AwsException(error_code="NeutronError",
                                          message=error_message)
Example #3
0
 def delete_elastic_ip(self, elastic_ip, dry_run=False):
     eid_addresses = self.get_elastic_addresses_by_elastic_ip(
         elastic_ip, dry_run)
     if len(eid_addresses) > 0:
         if 'AllocationId' in eid_addresses[0]:
             allocation_id = eid_addresses[0]['AllocationId']
     if allocation_id is None:
         raise exceptions.AwsException(error_code="Allocation ID",
                                       message="Allocation ID not found")
     return self._get_ec2_client().release_address(
         DryRun=dry_run, AllocationId=allocation_id)
Example #4
0
 def create_security_group(self, name, description, vpc_id, os_secgrp_id,
                           tags):
     if not description:
         description = 'Created by Platform9 OpenStack'
     secgrp = self._get_ec2_resource().create_security_group(
         GroupName=name, Description=description, VpcId=vpc_id)
     if self._create_sec_grp_tags(secgrp, tags) is False:
         delete_sec_grp(secgrp.id)
         raise exceptions.AwsException(
             message='Timed out creating tags on security group',
             error_code='Time Out')
     return secgrp
Example #5
0
 def disassociate_elastic_ip_from_ec2_instance(self,
                                               elastic_ip,
                                               dry_run=False):
     association_id = None
     eid_addresses = self.get_elastic_addresses_by_elastic_ip(
         elastic_ip, dry_run)
     if len(eid_addresses) > 0:
         if 'AssociationId' in eid_addresses[0]:
             association_id = eid_addresses[0]['AssociationId']
     if association_id is None:
         raise exceptions.AwsException(error_code="Association ID",
                                       message="Association ID not found")
     return self._get_ec2_client().disassociate_address(
         DryRun=dry_run, AssociationId=association_id)
Example #6
0
 def create_security_group_rules(self, ec2_secgrp, rules):
     if self._create_sec_grp_rules(ec2_secgrp, rules) is False:
         exceptions.AwsException(
             message='Timed out creating security groups',
             error_code='Time Out')