Exemplo n.º 1
0
    def run(self):
        try:
            ips = []
            nets = []
            for l in self.instance.links:
                ips.append(l['ip'])
                net = NetworkNode.fetchone(gid=l['network']['gid'],
                                           slice_id=self.lab_slice.id)
                nets.append(net)

            instance = self.instance
            public_ip, attrs = self.openstack.create_instance(
                instance.name, nets, ips, instance.configurations,
                self.sec_group_id, instance.image, instance.flavor)
            instance.update(status='active',
                            public_ip=public_ip,
                            cloud_attrs=attrs)
        except Exception as ex:
            error_type = 'Create instances error'
            error_msgs = [error_type + ': ' + str(ex)]

            lab = Lab.fetchone(id=self.lab_id)
            lab.update(status='deployfailed',
                       error_msgs=lab.error_msgs + error_msgs)
            raise Exception(error_type + str(error_msgs))
Exemplo n.º 2
0
def create_networks(cloudconfig, lab_id, lab_slice, topo):
    try:
        openstack = Openstack(cloudconfig.detail['openstackAuthURL'],
                              cloudconfig.detail['openstackProject'],
                              cloudconfig.detail['openstackUser'],
                              cloudconfig.detail['openstackPassword'])
        threads = []
        for n in topo['networks']:
            new_net = NetworkNode.insert(name=n['name'],
                                         cidr=n['cidr'],
                                         status='deploying',
                                         x=n['x'],
                                         y=n['y'],
                                         slice_id=lab_slice.id,
                                         gid=n['gid'])
            t = CreateNetThread(openstack, new_net)
            t.start()
            threads.append(t)

        for t in threads:
            t.join()
    except Exception as ex:
        error_type = 'Create networks error'
        error_msgs = [error_type + ': ' + str(ex)]

        lab = Lab.fetchone(id=lab_id)
        lab.update(status='deployfailed',
                   error_msgs=lab.error_msgs + error_msgs)
        raise Exception(
            error_type
        )  # Raise exception to not execute the next job in the dependency link
Exemplo n.º 3
0
def update_allowed_address_pairs(cloudconfig, lab_id, lab_slice, topo):
    try:
        openstack = Openstack(cloudconfig.detail['openstackAuthURL'],
                              cloudconfig.detail['openstackProject'],
                              cloudconfig.detail['openstackUser'],
                              cloudconfig.detail['openstackPassword'])
        mac_regex = '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
        ip_cidr_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4]' \
                        '[0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-' \
                        'f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-' \
                        '5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5' \
                        ']|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}((' \
                        '(:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0' \
                        '-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]' \
                        '{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0' \
                        '-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d' \
                        '|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1' \
                        ',4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d' \
                        '|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1' \
                        '\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(\/[0-9]{1,2})*$'
        for link in topo['links']:
            address_pairs = []
            network = NetworkNode.fetchone(gid=link['network']['gid'],
                                           slice_id=lab_slice.id)
            if link['target']['type'].lower() == 'instance':
                device = Instance.fetchone(gid=link['target']['gid'],
                                           slice_id=lab_slice.id)
            elif link['target']['type'].lower() == 'router':
                device = Router.fetchone(gid=link['target']['gid'],
                                         slice_id=lab_slice.id)
            else:
                continue
            for raw_address_pair in link.get('allowedAddressPairs', []):
                mac_address, ip_address, _ = (raw_address_pair + ',,').split(
                    ',', 2)
                if ip_address.strip() == '':
                    ip_address = mac_address
                    mac_address = ''
                if (mac_address == '' or re.match(
                        mac_regex, mac_address.strip())) and re.match(
                            ip_cidr_regex, ip_address.strip()):
                    address_pair = {'ip_address': ip_address}
                    if mac_address != '':
                        address_pair['mac_address'] = mac_address
                    address_pairs.append(address_pair)
            if address_pairs:
                openstack.update_allowed_address_pairs(
                    network, device.cloud_attrs['id'], address_pairs)

    except Exception as ex:
        error_type = 'Update allowed address pairs error'
        error_msgs = [error_type + ': ' + str(ex)]

        lab = Lab.fetchone(id=lab_id)
        lab.update(status='deployfailed',
                   error_msgs=lab.error_msgs + error_msgs)
        raise Exception(
            error_type
        )  # Raise exception to not execute the next job in the dependency link
Exemplo n.º 4
0
def delete_networks(cloudconfig, lab_id, lab_slice):
    try:
        openstack = Openstack(cloudconfig.detail['openstackAuthURL'],
                              cloudconfig.detail['openstackProject'],
                              cloudconfig.detail['openstackUser'],
                              cloudconfig.detail['openstackPassword'])
        networks = NetworkNode.fetchall(slice_id=lab_slice.id)
        threads = []
        for net in networks:
            t = DeleteNetworkThread(openstack, net)
            t.start()
            threads.append(t)
        for t in threads:
            t.join()
    except Exception as ex:
        error_type = 'Delete networks error'
        error_msgs = [error_type + ': ' + str(ex)]

        lab = Lab.fetchone(id=lab_id)
        lab.update(status='destroyfailed',
                   error_msgs=lab.error_msgs + error_msgs)
        raise Exception(
            error_type
        )  # Raise exception to not execute the next job in the dependency link