Esempio n. 1
0
 def remove_router_interface(self, router_id, subnet_id):
     add_itf = {"subnet_id": subnet_id}
     try:
         self.client.remove_interface_router(router_id, add_itf)
     except Conflict as e:
         error_n("Conflicting router interface request: %s", e)
         raise IntegrityException
Esempio n. 2
0
 def add_router_interface(self, router_id, subnet_id):
     add_itf = {"subnet_id": subnet_id}
     try:
         self.client.add_interface_router(router_id, add_itf)
     except BadRequest as e:
         error_n("Bad router interface request: %s", e)
         raise IntegrityException
Esempio n. 3
0
 def create_network(self, name, external=False):
     network = {'name': name, 'admin_state_up': True, 'router:external': external}
     try:
         return self.client.create_network({'network': network})['network']
     except Forbidden as f:
         error_n("Forbidden to create network: %s", f)
         raise IntegrityException
Esempio n. 4
0
    def associate_floating_ip(self, fip, port_id):
        try:
            update_fip = {'port_id': port_id}
            return self.client.update_floatingip(fip['id'], {'floatingip': update_fip})

        except (NotFound, BadRequest, IpAddressGenerationFailureClient) as e:
            error_n("Floating IP association failure: %s", e)
            raise IntegrityException
Esempio n. 5
0
    def allocate_floating_ip(self, network_id, port_id=None):
        try:
            if port_id:
                create_fip = {'floating_network_id': network_id, 'port_id': port_id}
            else:
                create_fip = {'floating_network_id': network_id}
            return self.client.create_floatingip({'floatingip': create_fip})['floatingip']

        except (NotFound, BadRequest, IpAddressGenerationFailureClient, OverQuotaClient) as e:
            error_n("Floating IP allocation failure: %s", e)
            raise IntegrityException
Esempio n. 6
0
    def boot(self, name, image, flavor, sg_names=None, network_id=None, meta=None, poll_for_completion=False):
        nics = [None] if network_id else None
        if network_id:
            nics[0] = {'net-id': network_id}

        try:
            # log_n('creating server: name=%s, image=%s, flavor=%s, sgs[0]=%s, nics=%s',
            #       name, image, flavor, sg_names[0] if sg_names else '-', nics)

            instance = self.client.servers.create(name, image, flavor, security_groups=sg_names,
                                                  nics=nics, meta=meta)
        except NovaForbidden as f:
            error_n('Nova boot forbidden: %s.', f)
            raise MiniCloudException
        except NovaClientException as nce:
            error_n('Nova boot exception: %s.', nce)
            raise MiniCloudException

        if poll_for_completion:
            while instance.status == 'BUILD':
                time.sleep(5)
                instance = self.server(instance.id)

        return instance
Esempio n. 7
0
 def delete_sg(self, sg):
     try:
         return self.client.security_groups.delete(sg)
     except NovaBadRequest as e:
         error_n('Nova exception: %s.', e)
         raise IntegrityException
Esempio n. 8
0
 def delete_router(self, router_id):
     try:
         self.client.delete_router(router_id)
     except Conflict as c:
         error_n("Delete router conflict: %s", c)
         raise IntegrityException