示例#1
0
def main():
    # initialize
    p = optparse.OptionParser(  version=version,\
                                description="This a driver interface for pyratemp configuration management. Version: %s" % version,\
                                conflict_handler="resolve"  )
    p.add_option('--ca', help="custom attribute name that has the meta configuration info.")
    (options,arguments) = p.parse_args()
    #ts = twistserver.TwistServer()
    #ServerService = ts.server.ServerService
    if options.ca:
        print "retrieving hardware dictionary...."
        hw = bs_hardware.construct_device_dictionary()
        sref = ServerRef(hw['mid'])
        sa = SAConfiguration(options.ca,sref,hw,service='ts.server.ServerService')
        action = ['genconfig','runcmds']
        if arguments:
            if re.match('(?i)genconfig',arguments[0]):
                print "\ndeploying configurations..."
                sa.deployConfigs()
                #print "\nrunning commands..."
                #sa.executeCommands() # by default if you generate configs
                #                     # you'll also execute any post cmds.
            elif re.match('(?i)runcmds',arguments[0]):
                sa.executeCommands()
        else:
            p.print_help()
            print "Please provide an action: %s" % action
    else:
        p.print_help()
示例#2
0
def runServerScript(script_id,
                    username,
                    jobNotify,
                    devices,
                    scriptArgs,
                    twist,
                    timeout=10):
    jobStarted = False
    time_offset = 5
    while not jobStarted:
        ssref = ServerScriptRef(script_id)
        ssService = twist.script.ServerScriptService
        ssJobArgs = ServerScriptJobArgs()
        ssJobArgs.targets = map(lambda x: ServerRef(x), devices)
        ssJobArgs.timeOut = timeout
        ssJobArgs.parameters = scriptArgs
        jobSchedule = JobSchedule()
        jobSchedule.startDate = int(time.time() + time_offset)
        try:
            jobId = ssService.startServerScript(ssref, ssJobArgs, username,
                                                jobNotify, jobSchedule).id
            jobStarted = True
        except PastScheduledDateException:
            print "Server Script (%s) is being rescheduled" % \
             ssService.getServerScriptVO(ssref).name
            jobStarted = False
            time_offset = time_offset + 5
    return jobId
示例#3
0
 def getvalue(self,objref,name):
     if re.match('^ipaddress(_[0-9])*$',name):    
         if re.match('^ipaddress_[0-9]$',name):
             (ipaddress,interface) = string.split(name,'_')
             return self.objref['interfaces'][int("%s" % interface)]['ip_address']
         else:
             #
             # Initialize servervo to get server specific information
             #
             from pytwist import twistserver
             from pytwist.com.opsware.server import ServerRef
             ts = twistserver.TwistServer()
             serverref = ServerRef(self.objref['mid'])
             servervo = ts.server.ServerService.getServerVO(serverref)
             return servervo.primaryIP
     elif re.match('^nodename$',name):
         return self.objref['system_name']
     elif re.match('^nodenum$',name):
         return re.match('([A-Za-z]+)([0-9]+)([A-Za-z])+',string.split(self.objref['system_name'],'-')[0]).group(2)
     elif re.match('^gateway$',name):
         return self.objref['default_gw']
     elif re.match('^netmask(_[0-9])*$',name):
         if re.match('^netmask_[0-9]$',name):
             (netmask,interface) = string.split(name,'_')
         else:
             ipaddress = name
             interface = 0
         return self.objref['interfaces'][int("%s" % interface)]['netmask']
     elif re.match('^macaddress(_[0-9])*$',name):
         if re.match('^macaddress_[0-9]$',name):
             (macaddress,interface) = string.split(name,'_')
         else:
             macaddress = name
             interface = 0
         return self.objref['interfaces'][int("%s" % interface)]['hw_addr']
     elif re.match('^dnsservers$',name):
         import simplejson
         return simplejson.dumps([ element for element in self.objref['device_dns_servers'] ])
     elif re.match('^domains$',name):
         import simplejson
         return simplejson.dumps([ element for element in self.objref['device_dns_search_domains'] ])
     elif re.match('^hw$',name):
         import simplejson
         return simplejson.dumps(self.objref)
     else:
         raise NoSuchHWFieldException,name
示例#4
0
def unset_prov_rule(svrid):
    # get the server's MAC address and facility
    svrref = ServerRef(svrid)
    try:
        svrvo = serverservice.getServerVO(svrref)
    except NotFoundException:
        raise librunplan.ShowErrorMessage(
            "Cound not find server record with ID %s" % svrid, EC_EXCEPTION)

    # get the server's facility (if the prov job is happening in a sat that defines
    # its own facility, the server's facility will not be the same as the buildmgr's)
    facilityref = svrvo.facility
    hwvo = serverservice.getServerHardwareVO(svrref)

    # to be safe, we'll clear the prov rule for all interfaces on the server
    # (it's too hard to tell which one it actually PXE boots off of)
    for interface in hwvo.interfaces:
        mac = interface.hardwareAddress
        unset_prov_rule_for_mac(mac, facilityref)
        filter.expression = 'ServerVO.hostName like "%s"' % (SEARCH_HOSTNAME)
    if SEARCH_ADDR:
        filter.expression='((device_interface_ip = "%s") | ' \
                          '(device_management_ip = "%s"))' % (SEARCH_ADDR,SEARCH_ADDR)
    if SEARCH_ALL:
        filter.expression='((ServerVO.name    like "%s") | ' \
                          '(ServerVO.hostName like "%s") | ' \
                          '(device_interface_ip =  "%s") | ' \
                          '(device_management_ip = "%s"))'   \
                          % (SEARCH_ALL,SEARCH_ALL,SEARCH_ALL,SEARCH_ALL)

    serverservice = ts.server.ServerService
    servers = serverservice.findServerRefs(filter)
elif MODE_OID:
    serverservice = ts.server.ServerService
    server = ServerRef(SEARCH_OID)
    servers = [server]

# Displaying response
if len(servers) < 1:
    sys.stderr.write("#- None server found !\n")
    sys.exit(3)

for server in servers:
    #pprint.pprint(inspect.getmembers(vo))
    #pprint.pprint(inspect.getmembers(script))
    if MODE_DETAIL:
        vo = serverservice.getServerVO(server)
        print "Server Name ........... " + vo.name
        print "Management IP ......... " + vo.managementIP
        print "HPSA Object ID ........ " + str(server.id)