Fixes the idf and pdf templates so that we can deploy opnfv
[pharos-tools.git] / laas-fog / pharoslaas / actions / vpn_make_user.py
1 ##############################################################################
2 # Copyright 2017 Parker Berberian and Others                                 #
3 #                                                                            #
4 # Licensed under the Apache License, Version 2.0 (the "License");            #
5 # you may not use this file except in compliance with the License.           #
6 # You may obtain a copy of the License at                                    #
7 #                                                                            #
8 #    http://www.apache.org/licenses/LICENSE-2.0                              #
9 #                                                                            #
10 # Unless required by applicable law or agreed to in writing, software        #
11 # distributed under the License is distributed on an "AS IS" BASIS,          #
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13 # See the License for the specific language governing permissions and        #
14 # limitations under the License.                                             #
15 ##############################################################################
16
17 import datetime
18 from vpnAction import VPNAction
19 import json
20
21
22 class Make_VPN_User(VPNAction):
23
24     def __init__(self, config=None):
25         super(Make_VPN_User, self).__init__(config=config)
26
27     def run(self, booking=None, user=None, passwd=None):
28         if user == "None":
29             user = None
30         if passwd == "None":
31             passwd = None
32         name, passwd, dn = self.makeNewUser(name=user, passwd=passwd)
33         vpn_info = {}
34         vpn_info['dn'] = dn
35         vpn_info['username'] = name
36         vpn_info['password'] = passwd
37         now = datetime.date.today()
38         vpn_info['created'] = now.isoformat()  # 'YYYY-MM-DD' today
39         self.action_service.set_value(
40                 name='vpn_'+name,
41                 value=json.dumps(vpn_info),
42                 local=False,
43                 encrypt=True
44                 )
45         if booking is not None:
46             self.addUserToBooking(vpn_info, booking)
47
48     def addUserToBooking(self, vpn_info, booking):
49         name = "booking_" + str(booking)
50         booking = json.loads(
51                 self.action_service.get_value(
52                     name=name,
53                     local=False
54                     )
55                 )
56         booking['vpn_key'] = "vpn_" + vpn_info['username']
57         self.action_service.set_value(
58                 name=name,
59                 value=json.dumps(booking),
60                 local=False
61                 )