Package Products :: Package ZenUtils :: Module LocationDump |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenUtils.LocationDump

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  __doc__="""LocationDump
    12
    13  Dump location data from pre 0.11.7 database to text to be reloaded
    14  in new location format
    15  """
    16
    17  from ZCmdBase import ZCmdBase
    18
    19 -class LocationDump(ZCmdBase):
    20      """
    21      Dump location data
    22      """
    23
    24 -    def dump(self):
    25          """
    26          Dump location data to the specified output file.
    27          """
    28          outfile = open(self.options.outfile, "w")
    29          if not hasattr(self.dataroot, "getSubDevices"):
    30              raise RuntimeError, "dataroot doesn't have getSubDevices"
    31          devs = self.dataroot.getSubDevices()
    32          for dev in devs:
    33              dcname = dev.getDataCenterName()
    34              rname = dev.getRackName()
    35              if rname:
    36                  locpath = dcname.split("-")
    37                  locpath.append(rname)
    38              else:
    39                  locpath = ("NoLocation",)
    40              line = "%s|%s\n" % (dev.getId(), "/" + "/".join(locpath))
    41              outfile.write(line)
    42          outfile.close()
    43
    44
    45 -    def buildOptions(self):
    46          """
    47          Command-line options for LocationDump
    48          """
    49          ZCmdBase.buildOptions(self)
    50          self.parser.add_option('-o', '--outfile',
    51                      dest='outfile',
    52                      default="locdump.out",
    53                      help='output file')
    54
    55
    56  if __name__ == "__main__":
    57      ld = LocationDump()
    58      ld.dump()
    59