Ejemplo n.º 1
0
 def onboard(self, devices, filters=None, wait_for_finish=True):
     interfaces = {'physical': [], 'logical': []}
     fq_name = ['default-global-system-config', 'device_import_template']
     payload = self.get_filters(filters)
     device_list = [device.uuid for device in devices]
     execution_id = self.vnc_h.execute_job(fq_name, payload, device_list)
     self.logger.info('Started onboarding devices %s' % devices)
     if wait_for_finish:
         status = self.wait_for_job_to_finish(':'.join(fq_name),
                                              execution_id)[0]
         assert status, 'job %s to onboard devices failed' % execution_id
         for device in devices:
             for port in device.get_physical_ports():
                 pif = PhysicalInterfaceFixture(
                     uuid=port, connections=self.connections)
                 pif._clear_cleanups()
                 pif.read()
                 interfaces['physical'].append(pif)
         for pif in interfaces['physical']:
             for port in pif.get_logical_ports():
                 lif = LogicalInterfaceFixture(uuid=port,
                                               connections=self.connections)
                 lif._clear_cleanups()
                 lif.read()
                 interfaces['logical'].append(lif)
         return execution_id, interfaces
     return execution_id, None
Ejemplo n.º 2
0
    def onboard_existing_fabric(self,
                                fabric_dict,
                                wait_for_finish=True,
                                name=None,
                                cleanup=False):
        interfaces = {'physical': [], 'logical': []}
        devices = list()

        name = get_random_name(name) if name else get_random_name('fabric')

        fq_name = [
            'default-global-system-config', 'existing_fabric_onboard_template'
        ]
        payload = {'fabric_fq_name': ["default-global-system-config", name],
                   'node_profiles': [{"node_profile_name": profile}
                       for profile in fabric_dict.get('node_profiles')\
                                      or NODE_PROFILES],
                   'device_auth': [{"username": cred['username'],
                                    "password": cred['password']}
                       for cred in fabric_dict['credentials']],
                   'overlay_ibgp_asn': fabric_dict['namespaces']['asn'][0]['min'],
                   'management_subnets': [{"cidr": mgmt["cidr"]}
                       for mgmt in fabric_dict['namespaces']['management']]
                  }
        self.logger.info('Onboarding existing fabric %s %s' % (name, payload))
        execution_id = self.vnc_h.execute_job(fq_name, payload)
        status, fabric = self._get_fabric_fixture(name)
        assert fabric, 'Create fabric seems to have failed'
        if cleanup:
            self.addCleanup(self.cleanup_fabric, fabric, devices, interfaces)
        if wait_for_finish:
            try:
                status = self.wait_for_job_to_finish(':'.join(fq_name),
                                                     execution_id)
            except AssertionError:
                self.cleanup_fabric(fabric, verify=False)
                raise
            assert status, 'job %s to create fabric failed' % execution_id
            for device in fabric.fetch_associated_devices() or []:
                device_fixture = PhysicalDeviceFixture(
                    connections=self.connections, name=device)
                device_fixture.read()
                device_fixture.add_csn()
                devices.append(device_fixture)
            for device in devices:
                for port in device.get_physical_ports():
                    pif = PhysicalInterfaceFixture(
                        uuid=port, connections=self.connections)
                    pif.read()
                    interfaces['physical'].append(pif)
            for pif in interfaces['physical']:
                for port in pif.get_logical_ports():
                    lif = LogicalInterfaceFixture(uuid=port,
                                                  connections=self.connections)
                    lif.read()
                    interfaces['logical'].append(lif)
        return (fabric, devices, interfaces)
Ejemplo n.º 3
0
    def onboard_existing_fabric(self, fabric_dict, wait_for_finish=True,
                                name=None, cleanup=False):
        interfaces = {'physical': [], 'logical': []}
        devices = list()
        
        name = get_random_name(name) if name else get_random_name('fabric')

        fq_name = ['default-global-system-config',
                   'existing_fabric_onboard_template']
        payload = {'fabric_fq_name': ["default-global-system-config", name],
                   'node_profiles': [{"node_profile_name": profile}
                       for profile in fabric_dict.get('node_profiles')\
                                      or NODE_PROFILES],
                   'device_auth': [{"username": cred['username'],
                                    "password": cred['password']}
                       for cred in fabric_dict['credentials']],
                   'overlay_ibgp_asn': fabric_dict['namespaces']['asn'][0]['min'],
                   'management_subnets': [{"cidr": mgmt["cidr"]}
                       for mgmt in fabric_dict['namespaces']['management']]
                  }
        self.logger.info('Onboarding existing fabric %s %s'%(name, payload))
        execution_id = self.vnc_h.execute_job(fq_name, payload)
        status, fabric = self._get_fabric_fixture(name)
        assert fabric, 'Create fabric seems to have failed'
        if cleanup:
            self.addCleanup(self.cleanup_fabric, fabric, devices, interfaces)
        if wait_for_finish:
            try:
                status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id)
            except AssertionError:
                self.cleanup_fabric(fabric, verify=False)
                raise
            assert status, 'job %s to create fabric failed'%execution_id
            for device in fabric.fetch_associated_devices() or []:
                device_fixture = PhysicalDeviceFixture(connections=self.connections,
                                                       name=device)
                device_fixture.read()
                device_fixture.add_csn()
                devices.append(device_fixture)
            for device in devices:
                for port in device.get_physical_ports():
                    pif = PhysicalInterfaceFixture(uuid=port, connections=self.connections)
                    pif.read()
                    interfaces['physical'].append(pif)
            for pif in interfaces['physical']:
                for port in pif.get_logical_ports():
                    lif = LogicalInterfaceFixture(uuid=port, connections=self.connections)
                    lif.read()
                    interfaces['logical'].append(lif)
        return (fabric, devices, interfaces)
Ejemplo n.º 4
0
 def onboard(self, devices, filters=None, wait_for_finish=True):
     interfaces = {'physical': [], 'logical': []}
     fq_name = ['default-global-system-config', 'device_import_template']
     payload = self.get_filters(filters)
     device_list = [device.uuid for device in devices]
     execution_id = self.vnc_h.execute_job(fq_name, payload, device_list)
     self.logger.info('Started onboarding devices %s'%devices)
     if wait_for_finish:
         status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id)
         assert status, 'job %s to onboard devices failed'%execution_id
         for device in devices:
             for port in device.get_physical_ports():
                 pif = PhysicalInterfaceFixture(uuid=port, connections=self.connections)
                 pif._clear_cleanups()
                 pif.read()
                 interfaces['physical'].append(pif)
         for pif in interfaces['physical']:
             for port in pif.get_logical_ports():
                 lif = LogicalInterfaceFixture(uuid=port, connections=self.connections)
                 lif._clear_cleanups()
                 lif.read()
                 interfaces['logical'].append(lif)
         return execution_id, interfaces
     return execution_id, None
Ejemplo n.º 5
0
    def onboard_fabric(self,
                       fabric_dict,
                       wait_for_finish=True,
                       name=None,
                       cleanup=False,
                       enterprise_style=True,
                       dc_asn=None,
                       serList=None):
        interfaces = {'physical': [], 'logical': []}
        devices = list()
        name = name if name else get_random_name('fabric')

        fq_name = ['default-global-system-config', 'fabric_onboard_template']
        if 'image_upgrade_os_version' in list(
                fabric_dict['namespaces'].keys()):
            self.logger.info("ZTP with image upgrade")
            os_version = fabric_dict['namespaces']['image_upgrade_os_version']
        else:
            self.logger.info("ZTP without image upgrade")
            os_version = ''

        payload = {'fabric_fq_name': ["default-global-system-config", name],
                   'fabric_display_name': name,
                   "supplemental_day_0_cfg":[{"name": dct["supplemental_day_0_cfg"]["name"],\
                                              "cfg": dct["supplemental_day_0_cfg"]["cfg"]}
                        for dct in list(self.inputs.physical_routers_data.values()) \
                           if dct.get('supplemental_day_0_cfg') \
                               if serList is None or dct["serial_number"] in serList],
                   'device_to_ztp': [{"serial_number": dct['serial_number'], \
                                      "hostname": dct['name'], \
                                      "supplemental_day_0_cfg": dct.get("supplemental_day_0_cfg",{}).get('name','')} \
                       for dct in list(self.inputs.physical_routers_data.values()) \
                           if dct.get('serial_number') \
                               if serList is None or dct["serial_number"] in serList],
                   'node_profiles': [{"node_profile_name": profile}
                       for profile in fabric_dict.get('node_profiles')\
                                      or NODE_PROFILES],
                   'device_auth': {"root_password": fabric_dict['credentials'][0]['password']},
                   'loopback_subnets': fabric_dict['namespaces']['loopback_subnets'],
                   'management_subnets': fabric_dict['namespaces']['management_subnets'],
                   'fabric_subnets': fabric_dict['namespaces']['fabric_subnets'],
                   'overlay_ibgp_asn': dc_asn or fabric_dict['namespaces']['overlay_ibgp_asn'],
                   'fabric_asn_pool': [{"asn_max": fabric_dict['namespaces']['asn'][0]['max'],
                                       "asn_min": fabric_dict['namespaces']['asn'][0]['min']}]
                   }
        if os_version:
            payload['os_version'] = os_version
        self.logger.info('Onboarding new fabric %s %s' % (name, payload))
        execution_id = self.vnc_h.execute_job(fq_name, payload)
        status, fabric = self._get_fabric_fixture(name)
        assert fabric, 'Create fabric seems to have failed'
        if cleanup:
            self.addCleanup(self.cleanup_fabric, fabric, devices, interfaces)
        if wait_for_finish:
            try:
                status = self.wait_for_job_to_finish(':'.join(fq_name),
                                                     execution_id)[0]
            except AssertionError:
                self.cleanup_fabric(fabric, verify=False)
                raise
            assert status, 'job %s to create fabric failed' % execution_id
            for device in fabric.fetch_associated_devices() or []:
                device_dict = self.get_prouter_dict(device)
                device_fixture = PhysicalDeviceFixture(
                    connections=self.connections, name=device)
                device_fixture.read()
                device_fixture.add_csn()
                devices.append(device_fixture)
            for device in devices:
                for port in device.get_physical_ports():
                    pif = PhysicalInterfaceFixture(
                        uuid=port, connections=self.connections)
                    pif.read()
                    interfaces['physical'].append(pif)
            for pif in interfaces['physical']:
                for port in pif.get_logical_ports():
                    lif = LogicalInterfaceFixture(uuid=port,
                                                  connections=self.connections)
                    lif.read()
                    interfaces['logical'].append(lif)
        return (fabric, devices, interfaces)