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.
25 gi
.require_version('RwDts', '1.0')
26 gi
.require_version('RwYang', '1.0')
27 gi
.require_version('RwResourceMgrYang', '1.0')
28 gi
.require_version('RwLaunchpadYang', '1.0')
29 gi
.require_version('RwcalYang', '1.0')
31 from gi
.repository
import (
39 from gi
.repository
.RwTypes
import RwStatus
41 import rift
.mano
.cloud
44 class ResourceMgrConfig(object):
45 XPATH_POOL_OPER_DATA
= "D,/rw-resource-mgr:resource-pool-records"
46 def __init__(self
, dts
, log
, rwlog_hdl
, loop
, parent
):
49 self
._rwlog
_hdl
= rwlog_hdl
53 self
._cloud
_sub
= None
57 yield from self
.register_resource_pool_operational_data()
58 self
.register_cloud_account_config()
60 def register_cloud_account_config(self
):
61 def on_add_cloud_account_apply(account
):
62 self
._log
.debug("Received on_add_cloud_account: %s", account
)
63 self
._parent
.add_cloud_account_config(account
)
65 def on_delete_cloud_account_apply(account_name
):
66 self
._log
.debug("Received on_delete_cloud_account_apply: %s", account_name
)
67 self
._parent
.delete_cloud_account_config(account_name
)
70 def on_delete_cloud_account_prepare(account_name
):
71 self
._log
.debug("Received on_delete_cloud_account_prepare: %s", account_name
)
72 self
._parent
.delete_cloud_account_config(account_name
, dry_run
=True)
74 cloud_callbacks
= rift
.mano
.cloud
.CloudAccountConfigCallbacks(
75 on_add_apply
=on_add_cloud_account_apply
,
76 on_delete_apply
=on_delete_cloud_account_apply
,
77 on_delete_prepare
=on_delete_cloud_account_prepare
,
80 self
._cloud
_sub
= rift
.mano
.cloud
.CloudAccountConfigSubscriber(
81 self
._dts
, self
._log
, self
._rwlog
_hdl
, cloud_callbacks
83 self
._cloud
_sub
.register()
86 def register_resource_pool_operational_data(self
):
88 def on_prepare(xact_info
, action
, ks_path
, msg
):
89 self
._log
.debug("ResourceMgr providing resource-pool information")
90 msg
= RwResourceMgrYang
.ResourcePoolRecords()
92 cloud_accounts
= self
._parent
.get_cloud_account_names()
93 for cloud_account_name
in cloud_accounts
:
94 pools
= self
._parent
.get_pool_list(cloud_account_name
)
95 self
._log
.debug("Publishing information about cloud account %s %d resource pools",
96 cloud_account_name
, len(pools
))
98 cloud_account_msg
= msg
.cloud_account
.add()
99 cloud_account_msg
.name
= cloud_account_name
101 pool_info
= self
._parent
.get_pool_info(cloud_account_name
, pool
.name
)
102 cloud_account_msg
.records
.append(pool_info
)
104 xact_info
.respond_xpath(rwdts
.XactRspCode
.ACK
,
105 ResourceMgrConfig
.XPATH_POOL_OPER_DATA
,
108 self
._log
.debug("Registering for Resource Mgr resource-pool-record using xpath: %s",
109 ResourceMgrConfig
.XPATH_POOL_OPER_DATA
)
111 handler
=rift
.tasklets
.DTS
.RegistrationHandler(on_prepare
=on_prepare
)
112 response
= yield from self
._dts
.register(xpath
=ResourceMgrConfig
.XPATH_POOL_OPER_DATA
,
114 flags
=rwdts
.Flag
.PUBLISHER
)