Ignore:
Timestamp:
May 24, 2010 7:12:13 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
8fc0606
Parents:
8dbbdc5
Message:

Add seer_master service. Other minor fixes and refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/emulab_access.py

    r8dbbdc5 r49051fb  
    9090        self.local_seer_image = config.get("access", "local_seer_image")
    9191        self.local_seer_start = config.get("access", "local_seer_start")
     92        self.seer_master_start = config.get("access", "seer_master_start")
    9293        self.ssh_privkey_file = config.get("access","ssh_privkey_file")
    9394        self.ssh_pubkey_file = config.get("access","ssh_pubkey_file")
     
    130131        # XXX: Configurable
    131132        self.exports = set(('SMB', 'seer', 'tmcd', 'userconfig',
    132             'project_export', 'local_seer_control'))
    133         self.imports = set(('SMB', 'seer', 'userconfig'))
    134 
    135         if not self.local_seer_image or not self.local_seer_software or \
    136                 not self.local_seer_start:
     133            'project_export', 'local_seer_control', 'seer_master'))
     134        self.imports = set(('SMB', 'seer', 'userconfig', 'seer_master'))
     135
     136        if not self.local_seer_image or not self.local_seer_software:
    137137            self.exports.discard('local_seer_control')
     138            self.exports.discard('seer_master')
     139
     140        if not self.local_seer_start:
     141            self.exports.discard('local_seer_control')
     142
     143        if not self.seer_master_start:
     144            self.exports.discard('seer_master')
    138145
    139146        if auth: self.auth = auth
     
    605612                }
    606613
     614    def export_seer_master(self, id, state, project, user):
     615        return {
     616                'id': id,
     617                'name': 'seer_master',
     618                'visibility': 'export',
     619                'server': 'http://seer_master:16606',
     620                }
     621
    607622    def export_tmcd(self, id, state, project, user):
    608623        return {
     
    657672                    elif sname == 'local_seer_control':
    658673                        exp.append(self.export_local_seer(id, state, project,
     674                            user))
     675                    elif sname == 'seer_master':
     676                        exp.append(self.export_seer_master(id, state, project,
    659677                            user))
    660678        return (exp, state)
     
    10551073            print >>f, "Service: %s" % s['name']
    10561074
     1075        def client_seer_master(f, s):
     1076            print >>f, 'PortalAlias: seer_master';
     1077
    10571078        def client_smb(f, s):
    10581079            print >>f, "Service: %s" % s['name']
     
    10791100                'userconfig': client_null,
    10801101                'project_export': client_null,
     1102                'seer_master': client_seer_master,
     1103            }
     1104
     1105        def client_seer_master_export(f, s):
     1106            print >>f, "AddedNode: seer_master"
     1107
     1108        def client_seer_local_export(f, s):
     1109            print >>f, "AddedNode: control"
     1110
     1111        client_export_service_out = {
     1112                'seer_master': client_seer_master_export,
     1113                'seer_local': client_seer_local_export,
    10811114            }
    10821115
     
    10961129                'project_export': server_null,
    10971130                'seer': server_seer,
     1131                'seer_master': server_port,
    10981132            }
    10991133        # XXX: end un hardcode this
     
    11091143        for e in [ e for e in topo.elements \
    11101144                if isinstance(e, topdl.Computer) and e.get_attribute('portal')]:
    1111             myname = e.name[0]
     1145            myname = e.name
    11121146            type = e.get_attribute('portal_type')
    11131147
     
    11671201                        s.get('visibility','') == 'import':
    11681202                    client_service_out[s['name']](f, s)
     1203                if s.get('name', '') in self.exports and \
     1204                        s.get('visibility', '') == 'export' and \
     1205                        s['name'] in client_export_service_out:
     1206                    client_export_service_out[s['name']](f, s)
    11691207            # Seer uses this.
    11701208            if mproj and meid:
     
    11921230                s = ""
    11931231                if isinstance(e, topdl.Computer):
    1194                     if self.node_info.has_key(e.name[0]):
    1195                         i = self.node_info[e.name[0]]
     1232                    if self.node_info.has_key(e.name):
     1233                        i = self.node_info[e.name]
    11961234                        for ifname, vlan, type in i:
    11971235                            for i in e.interface:
     
    12031241                                raise service_error(service_error.internal,
    12041242                                        "No interface %s on element %s" % \
    1205                                                 (ifname, e.name[0]))
     1243                                                (ifname, e.name))
    12061244                            # XXX: do netmask right
    12071245                            if type =='link':
    12081246                                s = ("tb-allow-external $%s dragonportal " + \
    12091247                                        "ip %s vlan %s netmask 255.255.255.0\n") % \
    1210                                         (e.name[0], addr, vlan)
     1248                                        (e.name, addr, vlan)
    12111249                            elif type =='lan':
    12121250                                s = ("tb-allow-external $%s dragonportal " + \
    12131251                                        "ip %s vlan %s usurp %s\n") % \
    1214                                         (e.name[0], addr, vlan, subs)
     1252                                        (e.name, addr, vlan, subs)
    12151253                            else:
    12161254                                raise service_error(service_error_internal,
     
    12231261
    12241262            def __call__(self, e):
    1225                 return e.name[0] not in self.nodes
     1263                return e.name not in self.nodes
    12261264
    12271265
     
    12841322                        e.set_attribute('startup', node_cmd)
    12851323
    1286                 dinf = [i[0] for i in dragon_map.get(e.name[0], []) ]
     1324                dinf = [i[0] for i in dragon_map.get(e.name, []) ]
    12871325                # Remove portal interfaces that do not connect to DRAGON
    12881326                e.interface = [i for i in e.interface \
     
    14151453                        'Bad Services missing info for import %s' % c)
    14161454
     1455    def configure_userconf(self, services):
     1456        """
     1457        If the userconf service was imported, collect the configuration data.
     1458        """
     1459        for s in services:
     1460            s_name = s.get('name', '')
     1461            s_vis = s.get('visibility','')
     1462            if s_name  == 'userconfig' and s_vis == 'import':
     1463                # Collect ther server and certificate info.
     1464                u = s.get('server', None)
     1465                for a in s.get('fedAttr', []):
     1466                    if a.get('attribute',"") == 'cert':
     1467                        cert = a.get('value', None)
     1468                        break
     1469                else:
     1470                    cert = None
     1471
     1472                if cert:
     1473                    # Make a temporary certificate file for get_url.  The
     1474                    # finally clause removes it whether something goes
     1475                    # wrong (including an exception from get_url) or not.
     1476                    try:
     1477                        tfos, tn = tempfile.mkstemp(suffix=".pem")
     1478                        tf = os.fdopen(tfos, 'w')
     1479                        print >>tf, cert
     1480                        tf.close()
     1481                        self.log.debug("Getting userconf info: %s" % u)
     1482                        get_url(u, tn, tmpdir, "userconf")
     1483                        self.log.debug("Got userconf info: %s" % u)
     1484                    except IOError, e:
     1485                        raise service_error(service.error.internal,
     1486                                "Cannot create temp file for " +
     1487                                "userconfig certificates: %s e")
     1488                    except:
     1489                        t, v, st = sys.exc_info()
     1490                        raise service_error(service_error.internal,
     1491                                "Error retrieving %s: %s" % (s, v))
     1492                    finally:
     1493                        if tn: os.remove(tn)
     1494                else:
     1495                    raise service_error(service_error.req,
     1496                            "No certificate for retreiving userconfig")
     1497                break
     1498
     1499    def add_seer_node(self, topo, name, startup):
     1500        """
     1501        Add a seer node to the given topology, with the startup command passed
     1502        in.
     1503        """
     1504        c_node = topdl.Computer(
     1505                name=name,
     1506                os= topdl.OperatingSystem(
     1507                    attribute=[
     1508                    { 'attribute': 'osid',
     1509                        'value': self.local_seer_image },
     1510                    ]),
     1511                attribute=[
     1512                    { 'attribute': 'startup', 'value': startup },
     1513                    ]
     1514                )
     1515        self.add_kit(c_node, self.local_seer_software)
     1516        topo.elements.append(c_node)
     1517
     1518    def configure_seer_services(self, services, topo, softdir):
     1519        local_seer = False
     1520        collect_seer = False
     1521        seer_master= False
     1522        for s in services:
     1523            s_name = s.get('name', '')
     1524            s_vis = s.get('visibility','')
     1525
     1526            if s_name  == 'local_seer_control'  and s_vis == 'export':
     1527                local_seer = True
     1528            elif s_name == 'seer_master':
     1529                if s_vis == 'import':
     1530                    collect_seer = True
     1531                elif s_vis == 'export':
     1532                    seer_master = True
     1533       
     1534        # We've got the whole picture now, so add nodes if needed and configure
     1535        # them to interconnect properly.
     1536        if local_seer or seer_master:
     1537            # Copy local seer control node software to the tempdir
     1538            for l, f in self.local_seer_software:
     1539                base = os.path.basename(f)
     1540                copy_file(f, "%s/%s" % (softdir, base))
     1541        # If we're collecting seers somewhere the controllers need to talk to
     1542        # the master.  In testbeds that export the service, that will be a
     1543        # local node that we'll add below.  Elsewhere it will be the control
     1544        # portal that will port forward to the exporting master.
     1545        if local_seer:
     1546            if collect_seer:
     1547                startup = "%s %s" % (self.local_seer_start, "seer_master")
     1548            else:
     1549                startup = self.local_seer_start
     1550            self.add_seer_node(topo, 'control', startup)
     1551        # If this is the seer master, add that node, too.
     1552        if seer_master:
     1553            self.add_seer_node(topo, 'seer_master', self.seer_master_start)
     1554
     1555
     1556
    14171557    def StartSegment(self, req, fid):
    14181558
     
    15241664            # If the userconf service was imported, collect the configuration
    15251665            # data.
    1526             for s in services:
    1527                 s_name = s.get('name', '')
    1528                 s_vis = s.get('visibility','')
    1529                 if s_name  == 'userconfig' and s_vis == 'import':
    1530                     # Collect ther server and certificate info.
    1531                     u = s.get('server', None)
    1532                     for a in s.get('fedAttr', []):
    1533                         if a.get('attribute',"") == 'cert':
    1534                             cert = a.get('value', None)
    1535                             break
    1536                     else:
    1537                         cert = None
    1538 
    1539                     if cert:
    1540                         # Make a temporary certificate file for get_url.  The
    1541                         # finally clause removes it whether something goes
    1542                         # wrong (including an exception from get_url) or not.
    1543                         try:
    1544                             tfos, tn = tempfile.mkstemp(suffix=".pem")
    1545                             tf = os.fdopen(tfos, 'w')
    1546                             print >>tf, cert
    1547                             tf.close()
    1548                             self.log.debug("Getting userconf info: %s" % u)
    1549                             get_url(u, tn, tmpdir, "userconf")
    1550                             self.log.debug("Got userconf info: %s" % u)
    1551                         except IOError, e:
    1552                             raise service_error(service.error.internal,
    1553                                     "Cannot create temp file for " +
    1554                                     "userconfig certificates: %s e")
    1555                         except:
    1556                             t, v, st = sys.exc_info()
    1557                             raise service_error(service_error.internal,
    1558                                     "Error retrieving %s: %s" % (s, v))
    1559                         finally:
    1560                             if tn: os.remove(tn)
    1561                     else:
    1562                         raise service_error(service_error.req,
    1563                                 "No certificate for retreiving userconfig")
    1564                     break
    1565                 if s_name  == 'local_seer_control'  and s_vis == 'export':
    1566                     # Copy local seer control node software to the tempdir
    1567                     for l, f in self.local_seer_software:
    1568                         base = os.path.basename(f)
    1569                         copy_file(f, "%s/%s" % (softdir, base))
    1570 
    1571                     # Add a control node to the local topology
    1572                     c_node = topdl.Computer(
    1573                             name='control',
    1574                             os= topdl.OperatingSystem(
    1575                                 attribute=[
    1576                                 { 'attribute': 'osid',
    1577                                     'value': self.local_seer_image },
    1578                                 ]),
    1579                             attribute=[
    1580                                 { 'attribute': 'startup',
    1581                                     'value': self.local_seer_start },
    1582                                 ]
    1583                             )
    1584                     self.add_kit(c_node, self.local_seer_software)
    1585                     topo.elements.append(c_node)
     1666            self.configure_userconf(services)
     1667            self.configure_seer_services(services, topo, softdir)
    15861668
    15871669            proj = None
Note: See TracChangeset for help on using the changeset viewer.