4 # Copyright 2016-2017 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 # TODO (Philip): Relook at this code
30 from gi
.repository
import (
37 logging
.basicConfig(level
=logging
.DEBUG
)
38 logger
= logging
.getLogger(__name__
)
40 model
= RwYang
.Model
.create_libncx()
41 model
.load_schema_ypbc(VldYang
.get_schema())
42 model
.load_schema_ypbc(NsdYang
.get_schema())
43 model
.load_schema_ypbc(VnfdYang
.get_schema())
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
)
52 logger
.debug("Sending VLD to netconf: %s", vld
)
53 proxy
.merge_config(vld
.to_xml_v2(model
))
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
)
62 logger
.debug("Sending VNFD to netconf: %s", vnfd
)
63 proxy
.merge_config(vnfd
.to_xml_v2(model
))
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
)
72 logger
.debug("Sending NSD to netconf: %s", nsd
)
73 proxy
.merge_config(nsd
.to_xml_v2(model
))
76 def parse_args(argv
=sys
.argv
[1:]):
77 """Create a parser which includes all generic demo arguments and parse args
80 argv - arguments to be parsed
82 Returns: List of parsed arguments
85 parser
= argparse
.ArgumentParser()
89 help="Hostname or IP where the confd netconf server is running.")
95 type=argparse
.FileType(),
96 #help="VLD XML File Path",
97 # We do not support uploading VLD separately
98 help=argparse
.SUPRESS
,
105 type=argparse
.FileType(),
106 help="VNFD XML File Path",
113 type=argparse
.FileType(),
114 help="VNFD XML File Path",
120 help="Logging is normally set to an INFO level. When this flag "
121 "is used logging is set to DEBUG. ")
123 args
= parser
.parse_args(argv
)
129 # Initialize Netconf Management Proxy
130 mgmt_proxy
= rift
.auto
.proxy
.NetconfProxy(args
.confd_host
)
133 # Ensure system started
134 vcs_component_info
= rift
.vcs
.mgmt
.VcsComponentInfo(mgmt_proxy
)
135 vcs_component_info
.wait_until_system_started()
142 proxy
= connect(args
)
143 for xml_file
in args
.vnfd_xml_file
:
144 configure_vnfd(proxy
, xml_file
)
146 for xml_file
in args
.vld_xml_file
:
147 configure_vld(proxy
, xml_file
)
149 for xml_file
in args
.nsd_xml_file
:
150 configure_nsd(proxy
, xml_file
)
153 if __name__
== "__main__":