84 lines
2.0 KiB
Python
84 lines
2.0 KiB
Python
![]() |
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||
|
# not use this file except in compliance with the License. You may obtain
|
||
|
# a copy of the License at
|
||
|
#
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
#
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||
|
# License for the specific language governing permissions and limitations
|
||
|
# under the License.
|
||
|
|
||
|
"""
|
||
|
Managing policies in the Cluster service.
|
||
|
|
||
|
For a full guide see
|
||
|
https://developer.openstack.org/sdks/python/openstacksdk/user/guides/cluster.html
|
||
|
"""
|
||
|
|
||
|
FAKE_NAME = 'test_receiver'
|
||
|
CLUSTER_ID = "ae63a10b-4a90-452c-aef1-113a0b255ee3"
|
||
|
|
||
|
|
||
|
def list_receivers(conn):
|
||
|
print("List Receivers:")
|
||
|
|
||
|
for receiver in conn.cluster.receivers():
|
||
|
print(receiver.to_dict())
|
||
|
|
||
|
for receiver in conn.cluster.receivers(sort='name:asc'):
|
||
|
print(receiver.to_dict())
|
||
|
|
||
|
|
||
|
def create_receiver(conn):
|
||
|
print("Create Receiver:")
|
||
|
|
||
|
# Build the receiver attributes and create the recever.
|
||
|
spec = {
|
||
|
"action": "CLUSTER_SCALE_OUT",
|
||
|
"cluster_id": CLUSTER_ID,
|
||
|
"name": FAKE_NAME,
|
||
|
"params": {
|
||
|
"count": "1"
|
||
|
},
|
||
|
"type": "webhook"
|
||
|
}
|
||
|
|
||
|
receiver = conn.cluster.create_receiver(**spec)
|
||
|
print(receiver.to_dict())
|
||
|
|
||
|
|
||
|
def get_receiver(conn):
|
||
|
print("Get Receiver:")
|
||
|
|
||
|
receiver = conn.cluster.get_receiver(FAKE_NAME)
|
||
|
print(receiver.to_dict())
|
||
|
|
||
|
|
||
|
def find_receiver(conn):
|
||
|
print("Find Receiver:")
|
||
|
|
||
|
receiver = conn.cluster.find_receiver(FAKE_NAME)
|
||
|
print(receiver.to_dict())
|
||
|
|
||
|
|
||
|
def update_receiver(conn):
|
||
|
print("Update Receiver:")
|
||
|
|
||
|
spec = {
|
||
|
"name": "test_receiver2",
|
||
|
"params": {
|
||
|
"count": "2"
|
||
|
}
|
||
|
}
|
||
|
receiver = conn.cluster.update_receiver(FAKE_NAME, **spec)
|
||
|
print(receiver.to_dict())
|
||
|
|
||
|
|
||
|
def delete_receiver(conn):
|
||
|
print("Delete Receiver:")
|
||
|
|
||
|
conn.cluster.delete_receiver(FAKE_NAME)
|
||
|
print("Receiver deleted.")
|