Docker build for SO
[osm/SO.git] / examples / ping_pong_ns / config_desc.py
1 #!/usr/bin/env python3
2
3 #
4 # Copyright 2016-2017 RIFT.IO Inc
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18
19 import argparse
20 import logging
21 import rift.auto.proxy
22 import rift.vcs
23 import sys
24
25 import gi
26 gi.require_version('RwYang', '1.0')
27
28 # TODO (Philip): Relook at this code
29
30 from gi.repository import (
31 NsdYang,
32 VldYang,
33 VnfdYang,
34 RwYang
35 )
36
37 logging.basicConfig(level=logging.DEBUG)
38 logger = logging.getLogger(__name__)
39
40 model = RwYang.Model.create_libyang()
41 model.load_schema_ypbc(VldYang.get_schema())
42 model.load_schema_ypbc(NsdYang.get_schema())
43 model.load_schema_ypbc(VnfdYang.get_schema())
44
45
46 def configure_vld(proxy, vld_xml_hdl):
47 vld_xml = vld_xml_hdl.read()
48 logger.debug("Attempting to deserialize XML into VLD protobuf: %s", vld_xml)
49 vld = VldYang.YangData_RwProject_Project_VldCatalog_Vld()
50 vld.from_xml_v2(model, vld_xml)
51
52 logger.debug("Sending VLD to netconf: %s", vld)
53 proxy.merge_config(vld.to_xml_v2(model))
54
55
56 def configure_vnfd(proxy, vnfd_xml_hdl):
57 vnfd_xml = vnfd_xml_hdl.read()
58 logger.debug("Attempting to deserialize XML into VNFD protobuf: %s", vnfd_xml)
59 vnfd = VnfdYang.YangData_VnfdCatalog_Vnfd()
60 vnfd.from_xml_v2(model, vnfd_xml)
61
62 logger.debug("Sending VNFD to netconf: %s", vnfd)
63 proxy.merge_config(vnfd.to_xml_v2(model))
64
65
66 def configure_nsd(proxy, nsd_xml_hdl):
67 nsd_xml = nsd_xml_hdl.read()
68 logger.debug("Attempting to deserialize XML into NSD protobuf: %s", nsd_xml)
69 nsd = NsdYang.YangData_NsdCatalog_Nsd()
70 nsd.from_xml_v2(model, nsd_xml)
71
72 logger.debug("Sending NSD to netconf: %s", nsd)
73 proxy.merge_config(nsd.to_xml_v2(model))
74
75
76 def parse_args(argv=sys.argv[1:]):
77 """Create a parser which includes all generic demo arguments and parse args
78
79 Arguments:
80 argv - arguments to be parsed
81
82 Returns: List of parsed arguments
83 """
84
85 parser = argparse.ArgumentParser()
86 parser.add_argument(
87 '--confd-host',
88 default="127.0.0.1",
89 help="Hostname or IP where the confd netconf server is running.")
90
91 parser.add_argument(
92 '--vld-xml-file',
93 action="append",
94 default=[],
95 type=argparse.FileType(),
96 #help="VLD XML File Path",
97 # We do not support uploading VLD separately
98 help=argparse.SUPRESS,
99 )
100
101 parser.add_argument(
102 '--vnfd-xml-file',
103 action="append",
104 default=[],
105 type=argparse.FileType(),
106 help="VNFD XML File Path",
107 )
108
109 parser.add_argument(
110 '--nsd-xml-file',
111 action="append",
112 default=[],
113 type=argparse.FileType(),
114 help="VNFD XML File Path",
115 )
116
117 parser.add_argument(
118 '-v', '--verbose',
119 action='store_true',
120 help="Logging is normally set to an INFO level. When this flag "
121 "is used logging is set to DEBUG. ")
122
123 args = parser.parse_args(argv)
124
125 return args
126
127
128 def connect(args):
129 # Initialize Netconf Management Proxy
130 mgmt_proxy = rift.auto.proxy.NetconfProxy(args.confd_host)
131 mgmt_proxy.connect()
132
133 # Ensure system started
134 vcs_component_info = rift.vcs.mgmt.VcsComponentInfo(mgmt_proxy)
135 vcs_component_info.wait_until_system_started()
136
137 return mgmt_proxy
138
139
140 def main():
141 args = parse_args()
142 proxy = connect(args)
143 for xml_file in args.vnfd_xml_file:
144 configure_vnfd(proxy, xml_file)
145
146 for xml_file in args.vld_xml_file:
147 configure_vld(proxy, xml_file)
148
149 for xml_file in args.nsd_xml_file:
150 configure_nsd(proxy, xml_file)
151
152
153 if __name__ == "__main__":
154 main()
155