4 # Copyright 2016 RIFT.IO Inc
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 import rift
.auto
.proxy
26 gi
.require_version('RwYang', '1.0')
28 from gi
.repository
import NsdYang
, VldYang
, VnfdYang
, RwYang
30 logging
.basicConfig(level
=logging
.DEBUG
)
31 logger
= logging
.getLogger(__name__
)
33 model
= RwYang
.Model
.create_libncx()
34 model
.load_schema_ypbc(VldYang
.get_schema())
35 model
.load_schema_ypbc(NsdYang
.get_schema())
36 model
.load_schema_ypbc(VnfdYang
.get_schema())
39 def configure_vld(proxy
, vld_xml_hdl
):
40 vld_xml
= vld_xml_hdl
.read()
41 logger
.debug("Attempting to deserialize XML into VLD protobuf: %s", vld_xml
)
42 vld
= VldYang
.YangData_Vld_VldCatalog_Vld()
43 vld
.from_xml_v2(model
, vld_xml
)
45 logger
.debug("Sending VLD to netconf: %s", vld
)
46 proxy
.merge_config(vld
.to_xml_v2(model
))
49 def configure_vnfd(proxy
, vnfd_xml_hdl
):
50 vnfd_xml
= vnfd_xml_hdl
.read()
51 logger
.debug("Attempting to deserialize XML into VNFD protobuf: %s", vnfd_xml
)
52 vnfd
= VnfdYang
.YangData_Vnfd_VnfdCatalog_Vnfd()
53 vnfd
.from_xml_v2(model
, vnfd_xml
)
55 logger
.debug("Sending VNFD to netconf: %s", vnfd
)
56 proxy
.merge_config(vnfd
.to_xml_v2(model
))
59 def configure_nsd(proxy
, nsd_xml_hdl
):
60 nsd_xml
= nsd_xml_hdl
.read()
61 logger
.debug("Attempting to deserialize XML into NSD protobuf: %s", nsd_xml
)
62 nsd
= NsdYang
.YangData_Nsd_NsdCatalog_Nsd()
63 nsd
.from_xml_v2(model
, nsd_xml
)
65 logger
.debug("Sending NSD to netconf: %s", nsd
)
66 proxy
.merge_config(nsd
.to_xml_v2(model
))
69 def parse_args(argv
=sys
.argv
[1:]):
70 """Create a parser which includes all generic demo arguments and parse args
73 argv - arguments to be parsed
75 Returns: List of parsed arguments
78 parser
= argparse
.ArgumentParser()
82 help="Hostname or IP where the confd netconf server is running.")
88 type=argparse
.FileType(),
89 help="VLD XML File Path",
96 type=argparse
.FileType(),
97 help="VNFD XML File Path",
104 type=argparse
.FileType(),
105 help="VNFD XML File Path",
111 help="Logging is normally set to an INFO level. When this flag "
112 "is used logging is set to DEBUG. ")
114 args
= parser
.parse_args(argv
)
120 # Initialize Netconf Management Proxy
121 mgmt_proxy
= rift
.auto
.proxy
.NetconfProxy(args
.confd_host
)
124 # Ensure system started
125 vcs_component_info
= rift
.vcs
.mgmt
.VcsComponentInfo(mgmt_proxy
)
126 vcs_component_info
.wait_until_system_started()
133 proxy
= connect(args
)
134 for xml_file
in args
.vnfd_xml_file
:
135 configure_vnfd(proxy
, xml_file
)
137 for xml_file
in args
.vld_xml_file
:
138 configure_vld(proxy
, xml_file
)
140 for xml_file
in args
.nsd_xml_file
:
141 configure_nsd(proxy
, xml_file
)
144 if __name__
== "__main__":