Ignore:
Timestamp:
Apr 21, 2010 5:31:03 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
f7a54c6
Parents:
f54e8e4
Message:

Get topology information into the info operation, as annotations of a topology description. This required adding such information to the start segment replies as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/local_emulab_segment.py

    rf54e8e4 rb4b19c7  
    9090$ns run
    9191"""
     92        self.node = { }
    9293
    9394    def get_state(self, pid, eid):
     
    138139            self.log.debug("State is %s" % state)
    139140            return state
     141
     142    def get_mapping(self, pid, eid):
     143        # command to test experiment state
     144        expinfo_exec = "/usr/testbed/bin/expinfo" 
     145        # The expinfo command.
     146        cmd = [ expinfo_exec, '-m', pid, eid]
     147
     148        dev_null = None
     149        try:
     150            dev_null = open("/dev/null", "a")
     151        except IOError, e:
     152            self.log.error("[get_state]: can't open /dev/null: %s" %e)
     153
     154        if self.debug:
     155            rv = 0
     156        else:
     157            self.log.debug("Getting mapping for %s %s" % (pid, eid))
     158            phys_start = re.compile('^Physical\s+Node\s+Mapping')
     159            phys_line = re.compile('(\S+)\s+\S+\s+\S+\s+(.*)')
     160            phys_end = re.compile('^$')
     161            status = subprocess.Popen(cmd, stdout=subprocess.PIPE,
     162                    stderr=dev_null, close_fds=True)
     163
     164            # Parse the info output.  Format:
     165            #
     166            # stuff
     167            # Physical Node Mapping:
     168            # ID              Type         OS              Physical   
     169            # --------------- ------------ --------------- ------------
     170            # virtual         dummy        dummy           physical
     171            #
     172            foundit = False
     173            skip = 0
     174            for line in status.stdout:
     175                if phys_start.match(line):
     176                    skip = 2
     177                    foundit = True
     178                elif not foundit:
     179                    continue
     180                elif skip > 0:
     181                    skip -= 1
     182                elif phys_end.match(line):
     183                    break
     184                else:
     185                    m = phys_line.match(line.strip())
     186                    if m: self.node[m.group(1)] = m.group(2)
     187                    else: self.log.warn(
     188                            "Matching failed while parsing node mapping")
     189            rv = status.wait()
     190
     191        # If the experiment is not present the subcommand returns a
     192        # non-zero return value.  If we successfully parsed a "none"
     193        # outcome, ignore the return code.
     194        if rv != 0 :
     195            raise service_error(service_error.internal,
     196                    "Cannot get node mapping of segment:%s/%s" % (pid, eid))
     197        else:
     198            return True
     199
    140200
    141201
     
    242302                state = self.get_state(pid, eid)
    243303                self.log.debug("[start_segment]: state is %s" % state)
    244                 return state == 'active'
     304                if state != 'active':
     305                    return False
    245306        # Everything has gone OK.
     307        self.get_mapping(pid,eid)
    246308        return True
    247309
Note: See TracChangeset for help on using the changeset viewer.