/usr/lib/python2.7/dist-packages/os_faults/drivers/cloud/devstack.py is in python-os-faults 0.1.17-0ubuntu1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | # 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.
import logging
from os_faults.ansible import executor
from os_faults.api import cloud_management
from os_faults.api import node_collection
from os_faults.api import node_discover
from os_faults.drivers.services import process
LOG = logging.getLogger(__name__)
class DevStackNode(node_collection.NodeCollection):
def connect(self, network_name):
raise NotImplementedError
def disconnect(self, network_name):
raise NotImplementedError
class ServiceInScreen(process.ServiceAsProcess):
"""Service in Screen
This driver controls service that is started in a window of
`screen` tool.
**Example configuration:**
.. code-block:: yaml
services:
app:
driver: screen
args:
window_name: app
grep: my_app
port: ['tcp', 4242]
parameters:
- **window_name** - name of a service
- **grep** - regexp for grep to find process PID
- **port** - tuple with two values - protocol, port number (optional)
"""
NAME = 'screen'
DESCRIPTION = 'Service in screen'
CONFIG_SCHEMA = {
'type': 'object',
'properties': {
'window_name': {'type': 'string'},
'grep': {'type': 'string'},
'port': process.PORT_SCHEMA,
},
'required': ['grep', 'window_name'],
'additionalProperties': False,
}
def __init__(self, *args, **kwargs):
super(ServiceInScreen, self).__init__(*args, **kwargs)
self.window_name = self.config['window_name']
# sends ctr+c, arrow up key, enter key
self.restart_cmd = (
"screen -S stack -p {window_name} -X "
"stuff $'\\003'$'\\033[A'$(printf \\\\r)").format(
window_name=self.window_name)
# sends ctr+c
self.terminate_cmd = (
"screen -S stack -p {window_name} -X "
"stuff $'\\003'").format(
window_name=self.window_name)
# sends arrow up key, enter key
self.start_cmd = (
"screen -S stack -p {window_name} -X "
"stuff $'\\033[A'$(printf \\\\r)").format(
window_name=self.window_name)
class DevStackManagement(cloud_management.CloudManagement,
node_discover.NodeDiscover):
"""Devstack driver.
This driver requires devstack installed in screen mode (USE_SCREEN=True).
Supports discovering of node MAC addresses.
**Example configuration:**
.. code-block:: yaml
cloud_management:
driver: devstack
args:
address: 192.168.1.10
username: ubuntu
password: ubuntu_pass
private_key_file: ~/.ssh/id_rsa_devstack
slaves:
- 192.168.1.11
- 192.168.1.12
iface: eth1
parameters:
- **address** - ip address of any devstack node
- **username** - username for all nodes
- **password** - password for all nodes (optional)
- **private_key_file** - path to key file (optional)
- **slaves** - list of ips for additional nodes (optional)
- **iface** - network interface name to retrieve mac address (optional)
- **serial** - how many hosts Ansible should manage at a single time.
(optional) default: 10
"""
NAME = 'devstack'
DESCRIPTION = 'DevStack management driver'
NODE_CLS = DevStackNode
SERVICES = {
'keystone': {
'driver': 'process',
'args': {
'grep': 'keystone-',
'restart_cmd': 'sudo service apache2 restart',
'terminate_cmd': 'sudo service apache2 stop',
'start_cmd': 'sudo service apache2 start',
}
},
'mysql': {
'driver': 'process',
'args': {
'grep': 'mysqld',
'restart_cmd': 'sudo service mysql restart',
'terminate_cmd': 'sudo service mysql stop',
'start_cmd': 'sudo service mysql start',
'port': ['tcp', 3307],
}
},
'rabbitmq': {
'driver': 'process',
'args': {
'grep': 'rabbitmq-server',
'restart_cmd': 'sudo service rabbitmq-server restart',
'terminate_cmd': 'sudo service rabbitmq-server stop',
'start_cmd': 'sudo service rabbitmq-server start',
}
},
'nova-api': {
'driver': 'screen',
'args': {
'grep': 'nova-api',
'window_name': 'n-api',
}
},
'glance-api': {
'driver': 'screen',
'args': {
'grep': 'glance-api',
'window_name': 'g-api',
}
},
'nova-compute': {
'driver': 'screen',
'args': {
'grep': 'nova-compute',
'window_name': 'n-cpu',
}
},
'nova-scheduler': {
'driver': 'screen',
'args': {
'grep': 'nova-scheduler',
'window_name': 'n-sch',
}
},
'ironic-api': {
'driver': 'screen',
'args': {
'grep': 'ironic-api',
'window_name': 'ir-api',
}
},
'ironic-conductor': {
'driver': 'screen',
'args': {
'grep': 'ironic-conductor',
'window_name': 'ir-cond',
}
},
}
SUPPORTED_NETWORKS = ['all-in-one']
CONFIG_SCHEMA = {
'type': 'object',
'$schema': 'http://json-schema.org/draft-04/schema#',
'properties': {
'address': {'type': 'string'},
'username': {'type': 'string'},
'password': {'type': 'string'},
'private_key_file': {'type': 'string'},
'slaves': {
'type': 'array',
'items': {'type': 'string'},
},
'iface': {'type': 'string'},
'serial': {'type': 'integer', 'minimum': 1},
},
'required': ['address', 'username'],
'additionalProperties': False,
}
def __init__(self, cloud_management_params):
super(DevStackManagement, self).__init__()
self.node_discover = self # supports discovering
self.address = cloud_management_params['address']
self.username = cloud_management_params['username']
self.private_key_file = cloud_management_params.get('private_key_file')
self.slaves = cloud_management_params.get('slaves', [])
self.iface = cloud_management_params.get('iface', 'eth0')
self.serial = cloud_management_params.get('serial')
self.cloud_executor = executor.AnsibleRunner(
remote_user=self.username, private_key_file=self.private_key_file,
password=cloud_management_params.get('password'),
become=False, serial=self.serial)
self.hosts = [node_collection.Host(ip=self.address)]
if self.slaves:
self.hosts.extend([node_collection.Host(ip=h)
for h in self.slaves])
self.nodes = None
def verify(self):
"""Verify connection to the cloud."""
nodes = self.get_nodes()
if nodes:
LOG.debug('DevStack nodes: %s', nodes)
LOG.info('Connected to cloud successfully')
def execute_on_cloud(self, hosts, task, raise_on_error=True):
"""Execute task on specified hosts within the cloud.
:param hosts: List of host FQDNs
:param task: Ansible task
:param raise_on_error: throw exception in case of error
:return: Ansible execution result (list of records)
"""
if raise_on_error:
return self.cloud_executor.execute(hosts, task)
else:
return self.cloud_executor.execute(hosts, task, [])
def discover_hosts(self):
if self.nodes is None:
get_mac_cmd = 'cat /sys/class/net/{}/address'.format(self.iface)
task = {'command': get_mac_cmd}
results = self.execute_on_cloud(self.hosts, task)
# TODO(astudenov): support fqdn
self.nodes = [node_collection.Host(ip=r.host,
mac=r.payload['stdout'],
fqdn='')
for r in results]
return self.nodes
|