Repository navigation
Expand file tree
/
Copy pathnode.py
More file actions
124 lines (107 loc) · 4.52 KB
/
Copy pathnode.py
File metadata and controls
124 lines (107 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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.
from openstack.cluster import cluster_service
from openstack import resource2 as resource
from openstack import utils
class Node(resource.Resource):
resource_key = 'node'
resources_key = 'nodes'
base_path = '/nodes'
service = cluster_service.ClusterService()
# capabilities
allow_create = True
allow_get = True
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
_query_mapping = resource.QueryParameters(
'show_details', 'name', 'sort', 'global_project', 'cluster_id',
'status')
# Properties
#: The name of the node.
name = resource.Body('name')
#: The ID of the physical object that backs the node.
physical_id = resource.Body('physical_id')
#: The ID of the cluster in which this node is a member.
#: A node is an orphan node if this field is empty.
cluster_id = resource.Body('cluster_id')
#: The ID of the profile used by this node.
profile_id = resource.Body('profile_id')
#: The ID of the user who created this node.
user_id = resource.Body('user')
#: The ID of the project this node belongs to.
project_id = resource.Body('project')
#: The name of the profile used by this node.
profile_name = resource.Body('profile_name')
#: An integer that is unique inside the owning cluster.
#: A value of -1 means this node is an orphan node.
index = resource.Body('index', type=int)
#: A string indicating the role the node plays in a cluster.
role = resource.Body('role')
#: The timestamp of the node object's initialization.
#: *Type: datetime object parsed from ISO 8601 formatted string*
init_at = resource.Body('init_at')
#: The timestamp of the node's creation, i.e. the physical object
#: represented by this node is also created.
#: *Type: datetime object parsed from ISO 8601 formatted string*
created_at = resource.Body('created_at')
#: The timestamp the node was last updated.
#: *Type: datetime object parsed from ISO 8601 formatted string*
updated_at = resource.Body('updated_at')
#: A string indicating the node's status.
status = resource.Body('status')
#: A string describing why the node entered its current status.
status_reason = resource.Body('status_reason')
#: A map containing key-value pairs attached to the node.
metadata = resource.Body('metadata', type=dict)
#: A map containing some runtime data for this node.
data = resource.Body('data', type=dict)
#: A map containing the details of the physical object this node
#: represents
details = resource.Body('details', type=dict)
#: A map containing the dependency of nodes
dependents = resource.Body('dependents', type=dict)
def _action(self, session, body):
"""Procedure the invoke an action API.
:param session: A session object used for sending request.
:param body: The body of action to be sent.
"""
url = utils.urljoin(self.base_path, self.id, 'actions')
resp = session.post(url, endpoint_filter=self.service, json=body)
return resp.json()
def check(self, session, **params):
"""An action procedure for the node to check its health status.
:param session: A session object used for sending request.
:returns: A dictionary containing the action ID.
"""
body = {
'check': params
}
return self._action(session, body)
def recover(self, session, **params):
"""An action procedure for the node to recover.
:param session: A session object used for sending request.
:returns: A dictionary containing the action ID.
"""
body = {
'recover': params
}
return self._action(session, body)
class NodeDetail(Node):
base_path = '/nodes/%(node_id)s?show_details=True'
allow_create = False
allow_get = True
allow_update = False
allow_delete = False
allow_list = False
node_id = resource.URI('node_id')