added zoni-cli
Found here: https://svn.apache.org/repos/asf/incubator/tashi/import/zoni-intel-r843/
This commit is contained in:
parent
ec0003bfa8
commit
68b51c7a0a
22 changed files with 3547 additions and 0 deletions
100
ssh/zoni-cli/pxe.py
Normal file
100
ssh/zoni-cli/pxe.py
Normal file
|
@ -0,0 +1,100 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
import datetime
|
||||
import subprocess
|
||||
import MySQLdb
|
||||
import traceback
|
||||
|
||||
from util import logit
|
||||
from bootmanagementinterface import BootManagementInterface
|
||||
|
||||
class Pxe(BootManagementInterface):
|
||||
def __init__(self, config, verbose=None):
|
||||
self.verbose = verbose
|
||||
self.host = config['dbHost']
|
||||
self.user = config['dbUser']
|
||||
self.passwd = config['dbPassword']
|
||||
self.db = config['dbInst']
|
||||
|
||||
self.tftpRootDir = config['tftpRootDir']
|
||||
self.tftpImageDir = config['tftpImageDir']
|
||||
self.tftpBootOptionsDir = config['tftpBootOptionsDir']
|
||||
self.tftpUpdateFile = config['tftpUpdateFile']
|
||||
self.tftpBaseFile = config['tftpBaseFile']
|
||||
self.tftpBaseMenuFile = config['tftpBaseMenuFile']
|
||||
|
||||
self.logFile = config['logFile']
|
||||
|
||||
if config['dbPort'] == "":
|
||||
config['dbPort'] = 3306
|
||||
|
||||
self.port = config['dbPort']
|
||||
|
||||
self.vlan_max = config['vlan_max']
|
||||
self.vlan_reserved = config['vlan_reserved']
|
||||
|
||||
# Connect to DB
|
||||
self.conn = MySQLdb.connect(host = self.host, port = self.port, user = self.user, passwd = self.passwd, db = self.db)
|
||||
#cursor.execute ("SELECT VERSION()")
|
||||
#print "server version:", row[0]
|
||||
#mysql -Dirp-cluster -hrodimus -u reader -e "select * from hostinfo;"
|
||||
|
||||
|
||||
|
||||
|
||||
''' This will create the update file tftpUpdateFile used to generate all the pxe boot files
|
||||
pass in a list of available images
|
||||
'''
|
||||
def createPxeUpdateFile (self, images):
|
||||
try:
|
||||
f = open(self.tftpUpdateFile, "w")
|
||||
except Exception:
|
||||
traceback.print_exc(sys.exc_info())
|
||||
|
||||
dadate = datetime.datetime.now().strftime("%Y%m%d.%H%M.%S")
|
||||
val = "# Generated by PRS : " + dadate
|
||||
f.write(val)
|
||||
for image in images:
|
||||
val = "\n# IMAGE " + image + "\n"
|
||||
f.write(val)
|
||||
base = "cat " + self.tftpBaseFile + " | sed 's/MAGIC1/" + image + "/' > " + self.tftpBootOptionsDir + "/" + image + "\n"
|
||||
basemenu= "cat " + self.tftpBaseMenuFile + " | sed 's/LABEL " + image + "/LABEL " + image + "\\n\\tMENU DEFAULT/' > " + self.tftpBootOptionsDir + "/" + image + "-menu\n"
|
||||
f.write(base)
|
||||
f.write(basemenu)
|
||||
f.close()
|
||||
|
||||
|
||||
def updatePxe(self):
|
||||
cmd = "chmod 755 " + self.tftpUpdateFile
|
||||
try:
|
||||
os.system(cmd)
|
||||
except Exception:
|
||||
traceback.print_exc(sys.exc_info())
|
||||
|
||||
cmd = self.tftpUpdateFile
|
||||
try:
|
||||
os.system(cmd)
|
||||
except Exception:
|
||||
traceback.print_exc(sys.exc_info())
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue