Exemplo n.º 1
0
    def build(self):
        """
        Build physical topology from the data.

        Args:
            filename: filename that defines physical topology
            data: python dictionary object to represent the physical topology

        """

        LOG.debug('-' * 80)
        LOG.debug("build")
        LOG.debug('-' * 80)
        #for b in self._bridges:
        #    bridge = b['bridge']
        #    # TODO(tomohiko) Need to something when not bridge['provided']?
        #    if bridge['provided']:
        #        LOG.info('Skipped building bridge=%r', bridge)

        midonet_api = self._midonet_api_host.get_midonet_api()

        # Check if TZ exists and pick it if that's the case
        tzones = midonet_api.get_tunnel_zones()
        tz = None
        for tzone in tzones:
            if tzone.get_name() == 'mdts-test':
                tz = tzone

        # IF TZ does not exists, create it
        if tz is None:
            if is_vxlan_enabled():
                tz = midonet_api.add_vxlan_tunnel_zone()
            else:
                tz = midonet_api.add_gre_tunnel_zone()
            tz.name('mdts-test')
            tz.create()

        for host in self._compute_hosts:
            tz_hosts = tz.get_hosts()
            tz_host = filter(
                lambda x: x.get_host_id() == host.get_midonet_host_id(),
                tz_hosts)
            if not tz_host:
                tz_host = tz.add_tunnel_zone_host()
                tz_host.ip_address(host.get_ip_address())
                tz_host.host_id(host.get_midonet_host_id())
                tz_host.create()

        # Create mapping between host['id'], interface['id'] with interface
        # description.
        for h in self._hosts:
            host = h['host']
            if 'mn_host_id' not in host:
                hostname = host.get('hostname')
                host_id = host.get('id')
                externalhost = next(external for external in self._external_hosts
                                    if external.get_hostname() == hostname)
                interfaces = host['interfaces']
                for interface in interfaces:
                    interface = interface['interface']
                    if interface['type'] == 'provided':
                        interface_id = interface.get('id')
                        iface = externalhost.create_provided(**interface)
                        self._interfaces[(host_id, interface_id)] = iface

        LOG.debug('-' * 80)
        LOG.debug("end build")
        LOG.debug('-' * 80)
Exemplo n.º 2
0
    def build(self):
        """
        Build physical topology from the data.

        Args:
            filename: filename that defines physical topology
            data: python dictionary object to represent the physical topology

        """

        LOG.debug('-' * 80)
        LOG.debug("build")
        LOG.debug('-' * 80)
        #for b in self._bridges:
        #    bridge = b['bridge']
        #    # TODO(tomohiko) Need to something when not bridge['provided']?
        #    if bridge['provided']:
        #        LOG.info('Skipped building bridge=%r', bridge)

        hosts = service.get_all_containers('midolman')
        midonet_api_host = service.get_container('midonet-api')
        midonet_api = midonet_api_host.get_midonet_api()

        if is_vxlan_enabled():
            tz = midonet_api.add_vxlan_tunnel_zone()
        else:
            tz = midonet_api.add_gre_tunnel_zone()
            tz.name('mdts-test')
            tz.create()

        for host in hosts:
            tz_host = tz.add_tunnel_zone_host()
            tz_host.ip_address(host.get_ip_address())
            tz_host.host_id(host.get_midonet_host_id())
            tz_host.create()

        # for h in self._hosts:
        #     host = h['host']
        #     host_container = service.load_from_name('midonet-agent.'+host['id'])
        #     if host.get('tunnel_zone'):
        #         tz_data = host.get('tunnel_zone')
        #         tzs = self._api.get_tunnel_zones()
        #
        #         # Ensure that TZ exists
        #         tz = [t for t in tzs if t.get_name() == tz_data['name']]
        #         if tz == []:
        #             if is_vxlan_enabled():
        #                 tz = self._api.add_vxlan_tunnel_zone()
        #             else:
        #                 tz = self._api.add_gre_tunnel_zone()
        #             tz.name(tz_data['name'])
        #             tz.create()
        #         else:
        #             tz = tz[0]
        #
        #         # Ensure that the host is in the TZ
        #         tz_hosts = tz.get_hosts()
        #         tz_host = filter(
        #             lambda x: x.get_host_id() == host['mn_host_id'],
        #             tz_hosts)
        #         if tz_host == []:
        #             tz_host = tz.add_tunnel_zone_host()
        #             tz_host.ip_address(tz_data['ip_addr'])
        #             tz_host.host_id(host['mn_host_id'])
        #             tz_host.create()

            #if host['provided'] == True:
            #    LOG.info('Skipped building host=%r', host)
            #else:
            #    #TODO(tomoe): when we support provisioning Midolman host with
            #    # this tool.
            #    pass
            #interfaces = host['interfaces']

            #futures = []
            #for i in interfaces:
            #    iface = Interface(i['interface'], host)
            #    self._interfaces[(host['id'], i['interface']['id'])] = iface
            #    f = iface.create()
            #    futures.append(f)

            #wait_on_futures(futures)

        LOG.debug('-' * 80)
        LOG.debug("end build")
        LOG.debug('-' * 80)
Exemplo n.º 3
0
    def build(self):
        """
        Build physical topology from the data.

        Args:
            filename: filename that defines physical topology
            data: python dictionary object to represent the physical topology

        """

        LOG.debug('-' * 80)
        LOG.debug("build")
        LOG.debug('-' * 80)
        for b in self._bridges:
            bridge = b['bridge']
            # TODO(tomohiko) Need to something when not bridge['provided']?
            if bridge['provided']:
                LOG.info('Skipped building bridge=%r', bridge)

        for h in self._hosts:
            host = h['host']
            if host.get('tunnel_zone'):
                tz_data = host.get('tunnel_zone')
                tzs = self._api.get_tunnel_zones()

                # Ensure that TZ exists
                tz = [t for t in tzs if t.get_name() == tz_data['name']]
                if tz == []:
                    if is_vxlan_enabled():
                        tz = self._api.add_vxlan_tunnel_zone()
                    else:
                        tz = self._api.add_gre_tunnel_zone()
                    tz.name(tz_data['name'])
                    tz.create()
                else:
                    tz = tz[0]

                # Ensure that the host is in the TZ
                tz_hosts = tz.get_hosts()
                tz_host = filter(
                    lambda x: x.get_host_id() == host['mn_host_id'], tz_hosts)
                if tz_host == []:
                    tz_host = tz.add_tunnel_zone_host()
                    tz_host.ip_address(tz_data['ip_addr'])
                    tz_host.host_id(host['mn_host_id'])
                    tz_host.create()

            if host['provided'] == True:
                LOG.info('Skipped building host=%r', host)
            else:
                #TODO(tomoe): when we support provisioning Midolman host with
                # this tool.
                pass
            interfaces = host['interfaces']

            futures = []
            for i in interfaces:
                iface = Interface(i['interface'], host)
                self._interfaces[(host['id'], i['interface']['id'])] = iface
                f = iface.create()
                futures.append(f)

            wait_on_futures(futures)

        LOG.debug('-' * 80)
        LOG.debug("end build")
        LOG.debug('-' * 80)
Exemplo n.º 4
0
    def build(self):
        """
        Build physical topology from the data.

        Args:
            filename: filename that defines physical topology
            data: python dictionary object to represent the physical topology

        """

        LOG.debug("-" * 80)
        LOG.debug("build")
        LOG.debug("-" * 80)
        for b in self._bridges:
            bridge = b["bridge"]
            # TODO(tomohiko) Need to something when not bridge['provided']?
            if bridge["provided"]:
                LOG.info("Skipped building bridge=%r", bridge)

        for h in self._hosts:
            host = h["host"]
            if host.get("tunnel_zone"):
                tz_data = host.get("tunnel_zone")
                tzs = self._api.get_tunnel_zones()

                # Ensure that TZ exists
                tz = [t for t in tzs if t.get_name() == tz_data["name"]]
                if tz == []:
                    if is_vxlan_enabled():
                        tz = self._api.add_vxlan_tunnel_zone()
                    else:
                        tz = self._api.add_gre_tunnel_zone()
                    tz.name(tz_data["name"])
                    tz.create()
                else:
                    tz = tz[0]

                # Ensure that the host is in the TZ
                tz_hosts = tz.get_hosts()
                tz_host = filter(lambda x: x.get_host_id() == host["mn_host_id"], tz_hosts)
                if tz_host == []:
                    tz_host = tz.add_tunnel_zone_host()
                    tz_host.ip_address(tz_data["ip_addr"])
                    tz_host.host_id(host["mn_host_id"])
                    tz_host.create()

            if host["provided"] == True:
                LOG.info("Skipped building host=%r", host)
            else:
                # TODO(tomoe): when we support provisioning Midolman host with
                # this tool.
                pass
            interfaces = host["interfaces"]

            futures = []
            for i in interfaces:
                iface = Interface(i["interface"], host)
                self._interfaces[(host["id"], i["interface"]["id"])] = iface
                f = iface.create()
                futures.append(f)

            wait_on_futures(futures)

        LOG.debug("-" * 80)
        LOG.debug("end build")
        LOG.debug("-" * 80)