3 # Copyright 2016 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 @author Varun Prasad (varun.prasad@riftio.com)
27 gi
.require_version('RwDts', '1.0')
28 gi
.require_version('RwPkgMgmtYang', '1.0')
31 from gi
.repository
import (
38 from .proxy
import filesystem
39 from . import publisher
as pkg_publisher
40 from . import subscriber
42 class PackageManagerTasklet(rift
.tasklets
.Tasklet
):
43 def __init__(self
, *args
, **kwargs
):
45 super().__init
__(*args
, **kwargs
)
46 self
.rwlog
.set_category("rw-mano-log")
47 self
.endpoint_rpc
= None
48 self
.schema_rpc
= None
49 except Exception as e
:
55 self
.log
.debug("Registering with dts")
57 self
.dts
= rift
.tasklets
.DTS(
59 RwPkgMgmtYang
.get_schema(),
61 self
.on_dts_state_change
64 proxy
= filesystem
.FileSystemProxy(self
.loop
, self
.log
)
66 args
= [self
.log
, self
.dts
, self
.loop
]
67 self
.job_handler
= pkg_publisher
.DownloadStatusPublisher(*args
)
69 # create catalog subscribers
70 self
.vnfd_catalog_sub
= subscriber
.VnfdStatusSubscriber(*args
)
71 self
.nsd_catalog_sub
= subscriber
.NsdStatusSubscriber(*args
)
74 self
.endpoint_rpc
= rpc
.EndpointDiscoveryRpcHandler(*args
)
75 self
.schema_rpc
= rpc
.SchemaRpcHandler(*args
)
76 self
.delete_rpc
= rpc
.PackageDeleteOperationsRpcHandler(*args
)
78 args
.append(self
.job_handler
)
79 self
.pkg_op
= rpc
.PackageOperationsRpcHandler(*args
)
84 except Exception as e
:
89 yield from self
.endpoint_rpc
.register()
90 yield from self
.schema_rpc
.register()
91 yield from self
.pkg_op
.register()
92 yield from self
.job_handler
.register()
93 yield from self
.delete_rpc
.register()
94 yield from self
.vnfd_catalog_sub
.register()
95 yield from self
.nsd_catalog_sub
.register()
102 def on_dts_state_change(self
, state
):
103 """Handle DTS state change
105 Take action according to current DTS state to transition application
106 into the corresponding application state
109 state - current dts state
113 rwdts
.State
.INIT
: rwdts
.State
.REGN_COMPLETE
,
114 rwdts
.State
.CONFIG
: rwdts
.State
.RUN
,
118 rwdts
.State
.INIT
: self
.init
,
119 rwdts
.State
.RUN
: self
.run
,
122 # Transition application to next state
123 handler
= handlers
.get(state
, None)
124 if handler
is not None:
127 # Transition dts to next state
128 next_state
= switch
.get(state
, None)
129 if next_state
is not None:
130 self
.dts
.handle
.set_state(next_state
)