Files
nodepool/nodepool/cmd/builder.py
James E. Blair 1dff39fccd Add REPL
As we continue to debug performance, it can be useful to have access
to a REPL as in Zuul.  Since there is no command socket in Nodepool
as there is in Zuul, the REPL must be engaged with a CLI argument
at startup.

Change-Id: Ieece1628494f79f39bd04216fc9ad7b725e541d8
2023-06-22 13:15:27 -07:00

73 lines
2.4 KiB
Python

# Licensed 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.
import signal
import sys
from nodepool import builder
import nodepool.cmd
import nodepool.lib.repl
class NodePoolBuilderApp(nodepool.cmd.NodepoolDaemonApp):
app_name = 'nodepool-builder'
app_description = 'NodePool Image Builder.'
def sigint_handler(self, signal, frame):
self.nb.stop()
sys.exit(0)
def create_parser(self):
parser = super(NodePoolBuilderApp, self).create_parser()
parser.add_argument('-c', dest='config',
default='/etc/nodepool/nodepool.yaml',
help='path to config file')
parser.add_argument('-s', dest='secure',
help='path to secure config file')
parser.add_argument('--build-workers', dest='build_workers',
default=1, help='number of build workers',
type=int)
parser.add_argument('--upload-workers', dest='upload_workers',
default=4, help='number of upload workers',
type=int)
parser.add_argument('--repl', action='store_true',
help="Start a REPL on port 3000")
return parser
def parse_args(self):
super(NodePoolBuilderApp, self).parse_args()
self.config_file = self.get_path(self.args.config)
self.secure_file = self.get_path(self.args.secure)
def run(self):
self.nb = builder.NodePoolBuilder(
self.config_file,
secure_path=self.secure_file,
num_builders=self.args.build_workers,
num_uploaders=self.args.upload_workers)
signal.signal(signal.SIGINT, self.sigint_handler)
self.nb.start()
if self.args.repl:
self.repl = nodepool.lib.repl.REPLServer(self.nb)
self.repl.start()
while True:
signal.pause()
def main():
return NodePoolBuilderApp.main()