Skip to content

Commit 48f413a

Browse files
authored
Merge pull request #2084 from shapeblue/passwd-speedup
Passwd speedup
2 parents 5f35c15 + 710d3bf commit 48f413a

5 files changed

Lines changed: 92 additions & 68 deletions

File tree

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,6 @@
4545
from cs.CsStaticRoutes import CsStaticRoutes
4646

4747

48-
class CsPassword(CsDataBag):
49-
50-
TOKEN_FILE="/tmp/passwdsrvrtoken"
51-
52-
def process(self):
53-
for item in self.dbag:
54-
if item == "id":
55-
continue
56-
self.__update(item, self.dbag[item])
57-
58-
def __update(self, vm_ip, password):
59-
token = ""
60-
try:
61-
tokenFile = open(self.TOKEN_FILE)
62-
token = tokenFile.read()
63-
except IOError:
64-
logging.debug("File %s does not exist" % self.TOKEN_FILE)
65-
66-
ips_cmd = "ip addr show | grep inet | awk '{print $2}'"
67-
ips = CsHelper.execute(ips_cmd)
68-
for ip in ips:
69-
server_ip = ip.split('/')[0]
70-
proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip])
71-
if proc.find():
72-
update_command = 'curl --header "DomU_Request: save_password" "http://{SERVER_IP}:8080/" -F "ip={VM_IP}" -F "password={PASSWORD}" ' \
73-
'-F "token={TOKEN}" >/dev/null 2>/dev/null &'.format(SERVER_IP=server_ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token)
74-
result = CsHelper.execute(update_command)
75-
logging.debug("Update password server result ==> %s" % result)
76-
77-
7848
class CsAcl(CsDataBag):
7949
"""
8050
Deal with Network acls
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/python
2+
# -- coding: utf-8 --
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
import CsHelper
21+
from CsProcess import CsProcess
22+
from netaddr import IPNetwork, IPAddress
23+
import logging
24+
25+
26+
class CsPassword:
27+
28+
TOKEN_FILE="/tmp/passwdsrvrtoken"
29+
30+
def __init__(self, dbag):
31+
self.dbag = dbag
32+
self.process()
33+
34+
def process(self):
35+
self.__update(self.dbag['ip_address'], self.dbag['password'])
36+
37+
def __update(self, vm_ip, password):
38+
token = ""
39+
try:
40+
tokenFile = open(self.TOKEN_FILE)
41+
token = tokenFile.read()
42+
except IOError:
43+
logging.debug("File %s does not exist" % self.TOKEN_FILE)
44+
45+
logging.debug("Got VM '%s' and password '%s'" % (vm_ip, password))
46+
get_cidrs_cmd = "ip addr show | grep inet | grep -v secondary | awk '{print $2}'"
47+
cidrs = CsHelper.execute(get_cidrs_cmd)
48+
logging.debug("Found these CIDRs: %s" % cidrs)
49+
for cidr in cidrs:
50+
logging.debug("Processing CIDR '%s'" % cidr)
51+
if IPAddress(vm_ip) in IPNetwork(cidr):
52+
ip = cidr.split('/')[0]
53+
logging.debug("Cidr %s matches vm ip address %s so adding passwd to passwd server at %s" % (cidr, vm_ip, ip))
54+
proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', ip])
55+
if proc.find():
56+
update_command = 'curl --header "DomU_Request: save_password" "http://{SERVER_IP}:8080/" -F "ip={VM_IP}" -F "password={PASSWORD}" ' \
57+
'-F "token={TOKEN}" --interface 127.0.0.1 >/dev/null 2>/dev/null &'.format(SERVER_IP=ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token)
58+
result = CsHelper.execute(update_command)
59+
logging.debug("Update password server result ==> %s" % result)
60+
else:
61+
logging.debug("Update password server skipped because we didn't find a passwd server process for %s (makes sense on backup routers)" % ip)

systemvm/patches/debian/config/opt/cloud/bin/cs_vmp.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

systemvm/patches/debian/config/opt/cloud/bin/merge.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import cs_ip
2424
import cs_guestnetwork
2525
import cs_cmdline
26-
import cs_vmp
2726
import cs_network_acl
2827
import cs_firewallrules
2928
import cs_loadbalancer
@@ -36,8 +35,6 @@
3635
import cs_vpnusers
3736
import cs_staticroutes
3837

39-
from pprint import pprint
40-
4138

4239
class DataBag:
4340

@@ -105,8 +102,6 @@ def process(self):
105102
dbag = self.processGuestNetwork(self.db.getDataBag())
106103
elif self.qFile.type == 'cmdline':
107104
dbag = self.processCL(self.db.getDataBag())
108-
elif self.qFile.type == 'vmpassword':
109-
dbag = self.processVMpassword(self.db.getDataBag())
110105
elif self.qFile.type == 'networkacl':
111106
dbag = self.process_network_acl(self.db.getDataBag())
112107
elif self.qFile.type == 'firewallrules':
@@ -188,9 +183,6 @@ def process_monitorservice(self, dbag):
188183
def process_staticroutes(self, dbag):
189184
return cs_staticroutes.merge(dbag, self.qFile.data)
190185

191-
def processVMpassword(self, dbag):
192-
return cs_vmp.merge(dbag, self.qFile.data)
193-
194186
def processForwardingRules(self, dbag):
195187
# to be used by both staticnat and portforwarding
196188
return cs_forwardingrules.merge(dbag, self.qFile.data)
@@ -275,13 +267,21 @@ class QueueFile:
275267
fileName = ''
276268
configCache = "/var/cache/cloud"
277269
keep = True
270+
do_merge = True
278271
data = {}
279272

273+
def update_databag(self):
274+
if self.do_merge:
275+
logging.info("Merging because do_merge is %s" % self.do_merge)
276+
updateDataBag(self)
277+
else:
278+
logging.info("Not merging because do_merge is %s" % self.do_merge)
279+
280280
def load(self, data):
281281
if data is not None:
282282
self.data = data
283283
self.type = self.data["type"]
284-
proc = updateDataBag(self)
284+
self.update_databag()
285285
return
286286
fn = self.configCache + '/' + self.fileName
287287
try:
@@ -296,7 +296,7 @@ def load(self, data):
296296
self.__moveFile(fn, self.configCache + "/processed")
297297
else:
298298
os.remove(fn)
299-
proc = updateDataBag(self)
299+
self.update_databag()
300300

301301
def setFile(self, name):
302302
self.fileName = name

systemvm/patches/debian/config/opt/cloud/bin/update_config.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os.path
2626
import configure
2727
import json
28+
from cs.CsVmPassword import *
2829

2930
logging.basicConfig(filename='/var/log/cloud.log', level=logging.DEBUG, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s')
3031

@@ -45,15 +46,30 @@ def finish_config():
4546
sys.exit(returncode)
4647

4748

48-
def process_file():
49+
def process(do_merge=True):
4950
print "[INFO] Processing JSON file %s" % sys.argv[1]
5051
qf = QueueFile()
5152
qf.setFile(sys.argv[1])
53+
qf.do_merge = do_merge
5254
qf.load(None)
55+
56+
return qf
57+
58+
59+
def process_file():
60+
print "[INFO] process_file"
61+
qf = process()
5362
# Converge
5463
finish_config()
5564

5665

66+
def process_vmpasswd():
67+
print "[INFO] process_vmpassword"
68+
qf = process(False)
69+
print "[INFO] Sending password to password server"
70+
CsPassword(qf.getData())
71+
72+
5773
def is_guestnet_configured(guestnet_dict, keys):
5874

5975
existing_keys = []
@@ -135,6 +151,10 @@ def is_guestnet_configured(guestnet_dict, keys):
135151
else:
136152
print "[INFO] update_config.py :: No GuestNetwork configured yet. Configuring first one now."
137153
process_file()
154+
# Bypass saving passwords and running full config/convergence, just feed passwd to passwd server and stop
155+
elif sys.argv[1].startswith("vm_password.json"):
156+
print "[INFO] update_config.py :: Processing incoming vm_passwd file => %s" % sys.argv[1]
157+
process_vmpasswd()
138158
else:
139159
print "[INFO] update_config.py :: Processing incoming file => %s" % sys.argv[1]
140160
process_file()

0 commit comments

Comments
 (0)