Merge "Create systemwide lock for glean"
This commit is contained in:
commit
bea0c3733a
15
glean/cmd.py
15
glean/cmd.py
|
@ -23,6 +23,8 @@ import subprocess
|
|||
import sys
|
||||
import time
|
||||
|
||||
from glean import systemlock
|
||||
|
||||
post_up = " post-up route add -net {net} netmask {mask} gw {gw} || true\n"
|
||||
pre_down = " pre-down route del -net {net} netmask {mask} gw {gw} || true\n"
|
||||
|
||||
|
@ -412,12 +414,13 @@ def main():
|
|||
'--skip-network', dest='skip', action='store_true',
|
||||
help="Do not write network info")
|
||||
args = parser.parse_args()
|
||||
if args.ssh:
|
||||
write_ssh_keys(args)
|
||||
if args.hostname:
|
||||
set_hostname_from_config_drive(args)
|
||||
if args.interface != 'lo' and not args.skip:
|
||||
write_network_info_from_config_drive(args)
|
||||
with systemlock.Lock(os.path.join(args.root, 'tmp/glean.lock')):
|
||||
if args.ssh:
|
||||
write_ssh_keys(args)
|
||||
if args.hostname:
|
||||
set_hostname_from_config_drive(args)
|
||||
if args.interface != 'lo' and not args.skip:
|
||||
write_network_info_from_config_drive(args)
|
||||
return 0
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/python
|
||||
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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 fcntl
|
||||
|
||||
|
||||
class Lock(object):
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
|
||||
def __enter__(self):
|
||||
fh = open(self.filename, 'w')
|
||||
fcntl.flock(fh, fcntl.LOCK_EX)
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
fh = open(self.filename, 'w')
|
||||
fcntl.flock(fh, fcntl.LOCK_UN)
|
Loading…
Reference in New Issue