Exemple #1
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)
    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)
 def discover(self, fabric, wait_for_finish=True):
     devices = list()
     fq_name = ['default-global-system-config', 'discover_device_template']
     payload = {'fabric_uuid': fabric.uuid}
     execution_id = self.vnc_h.execute_job(fq_name, payload)
     self.logger.info('Started device discovery for fabric %s'%(
                      fabric.name))
     self.addCleanup(self.cleanup_discover, fabric, devices)
     if wait_for_finish:
         status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id)
         assert status, 'job %s to discover devices 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)
         self.logger.info('discovered devices %s for fabric %s'%(
                          devices, fabric.name))
     return execution_id, devices
 def discover(self, fabric, wait_for_finish=True):
     devices = list()
     fq_name = ['default-global-system-config', 'discover_device_template']
     payload = {'fabric_uuid': fabric.uuid}
     execution_id = self.vnc_h.execute_job(fq_name, payload)
     self.logger.info('Started device discovery for fabric %s'%(
                      fabric.name))
     self.addCleanup(self.cleanup_discover, fabric, devices)
     if wait_for_finish:
         status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id)
         assert status, 'job %s to discover devices 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)
         self.logger.info('discovered devices %s for fabric %s'%(
                          devices, fabric.name))
     return execution_id, devices
Exemple #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)