This file is indexed.

/usr/lib/python2.7/dist-packages/os_faults/drivers/cloud/fuel.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# 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 json
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

LOG = logging.getLogger(__name__)


class FuelNodeCollection(node_collection.NodeCollection):

    def connect(self, network_name):
        LOG.info("Connect network '%s' on nodes: %s", network_name, self)
        task = {'fuel_network_mgmt': {
            'network_name': network_name,
            'operation': 'up',
        }}
        self.cloud_management.execute_on_cloud(self.hosts, task)

    def disconnect(self, network_name):
        LOG.info("Disconnect network '%s' on nodes: %s",
                 network_name, self)
        task = {'fuel_network_mgmt': {
            'network_name': network_name,
            'operation': 'down',
        }}
        self.cloud_management.execute_on_cloud(self.hosts, task)


class FuelManagement(cloud_management.CloudManagement,
                     node_discover.NodeDiscover):
    """Fuel driver.

    Cloud deployed by fuel. Supports discovering of slave nodes.

    **Example configuration:**

    .. code-block:: yaml

        cloud_management:
          driver: fuel
          args:
            address: 192.168.1.10
            username: root
            private_key_file: ~/.ssh/id_rsa_fuel
            slave_direct_ssh: True

    parameters:

    - **address** - ip address of fuel master node
    - **username** - username for fuel master and slave nodes
    - **private_key_file** - path to key file (optional)
    - **slave_direct_ssh** - if *False* then fuel master is used as ssh proxy
      (optional)
    - **serial** - how many hosts Ansible should manage at a single time.
      (optional) default: 10
    """

    NAME = 'fuel'
    DESCRIPTION = 'Fuel 9.x cloud management driver'
    NODE_CLS = FuelNodeCollection
    SERVICES = {
        'keystone': {
            'driver': 'linux_service',
            'args': {
                'grep': 'keystone',
                'linux_service': 'apache2',
            }
        },
        'horizon': {
            'driver': 'linux_service',
            'args': {
                'grep': 'apache2',
                'linux_service': 'apache2',
            }
        },
        'memcached': {
            'driver': 'linux_service',
            'args': {
                'grep': 'memcached',
                'linux_service': 'memcached',
            }
        },
        'mysql': {
            'driver': 'pcs_service',
            'args': {
                'grep': 'mysqld',
                'pcs_service': 'p_mysqld',
                'port': ['tcp', 3307],
            }
        },
        'rabbitmq': {
            'driver': 'pcs_service',
            'args': {
                'grep': 'rabbit tcp_listeners',
                'pcs_service': 'p_rabbitmq-server',
            }
        },
        'glance-api': {
            'driver': 'linux_service',
            'args': {
                'grep': 'glance-api',
                'linux_service': 'glance-api',
            }
        },
        'glance-glare': {
            'driver': 'linux_service',
            'args': {
                'grep': 'glance-glare',
                'linux_service': 'glance-glare',
            }
        },
        'glance-registry': {
            'driver': 'linux_service',
            'args': {
                'grep': 'glance-registry',
                'linux_service': 'glance-registry',
            }
        },
        'nova-api': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-api',
                'linux_service': 'nova-api',
            }
        },
        'nova-compute': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-compute',
                'linux_service': 'nova-compute',
            }
        },
        'nova-scheduler': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-scheduler',
                'linux_service': 'nova-scheduler',
            }
        },
        'nova-cert': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-cert',
                'linux_service': 'nova-cert',
            }
        },
        'nova-conductor': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-conductor',
                'linux_service': 'nova-conductor',
            }
        },
        'nova-consoleauth': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-consoleauth',
                'linux_service': 'nova-consoleauth',
            }
        },
        'nova-novncproxy': {
            'driver': 'linux_service',
            'args': {
                'grep': 'nova-novncproxy',
                'linux_service': 'nova-novncproxy',
            }
        },
        'neutron-server': {
            'driver': 'linux_service',
            'args': {
                'grep': 'neutron-server',
                'linux_service': 'neutron-server',
            }
        },
        'neutron-dhcp-agent': {
            'driver': 'pcs_service',
            'args': {
                'grep': 'neutron-dhcp-agent',
                'pcs_service': 'neutron-dhcp-agent',
            }
        },
        'neutron-metadata-agent': {
            'driver': 'pcs_or_linux_service',
            'args': {
                'grep': 'neutron-metadata-agent',
                'pcs_service': 'neutron-metadata-agent',
                'linux_service': 'neutron-metadata-agent',
            }
        },
        'neutron-openvswitch-agent': {
            'driver': 'pcs_or_linux_service',
            'args': {
                'grep': 'neutron-openvswitch-agent',
                'pcs_service': 'neutron-openvswitch-agent',
                'linux_service': 'neutron-openvswitch-agent',
            }
        },
        'neutron-l3-agent': {
            'driver': 'pcs_or_linux_service',
            'args': {
                'grep': 'neutron-l3-agent',
                'pcs_service': 'neutron-l3-agent',
                'linux_service': 'neutron-l3-agent',
            }
        },
        'heat-api': {
            'driver': 'linux_service',
            'args': {
                'grep': 'heat-api',
                'linux_service': 'heat-api',
            }
        },
        'heat-engine': {
            'driver': 'pcs_service',
            'args': {
                'grep': 'heat-engine',
                'pcs_service': 'p_heat-engine',
            }
        },
        'cinder-api': {
            'driver': 'linux_service',
            'args': {
                'grep': 'cinder-api',
                'linux_service': 'cinder-api',
            }
        },
        'cinder-scheduler': {
            'driver': 'linux_service',
            'args': {
                'grep': 'cinder-scheduler',
                'linux_service': 'cinder-scheduler',
            }
        },
        'cinder-volume': {
            'driver': 'linux_service',
            'args': {
                'grep': 'cinder-volume',
                'linux_service': 'cinder-volume',
            }
        },
        'cinder-backup': {
            'driver': 'linux_service',
            'args': {
                'grep': 'cinder-backup',
                'linux_service': 'cinder-backup',
            }
        },
        'ironic-api': {
            'driver': 'linux_service',
            'args': {
                'grep': 'ironic-api',
                'linux_service': 'ironic-api',
            }
        },
        'ironic-conductor': {
            'driver': 'linux_service',
            'args': {
                'grep': 'ironic-conductor',
                'linux_service': 'ironic-conductor',
            }
        },
        'swift-account': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-account',
                'linux_service': 'swift-account',
            }
        },
        'swift-account-auditor': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-account-auditor',
                'linux_service': 'swift-account-auditor',
            }
        },
        'swift-account-reaper': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-account-reaper',
                'linux_service': 'swift-account-reaper',
            }
        },
        'swift-account-replicator': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-account-replicator',
                'linux_service': 'swift-account-replicator',
            }
        },
        'swift-container': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-container',
                'linux_service': 'swift-container',
            }
        },
        'swift-container-auditor': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-container-auditor',
                'linux_service': 'swift-container-auditor',
            }
        },
        'swift-container-replicator': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-container-replicator',
                'linux_service': 'swift-container-replicator',
            }
        },
        'swift-container-sync': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-container-sync',
                'linux_service': 'swift-container-sync',
            }
        },
        'swift-container-updater': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-container-updater',
                'linux_service': 'swift-container-updater',
            }
        },
        'swift-object': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-object',
                'linux_service': 'swift-object',
            }
        },
        'swift-object-auditor': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-object-auditor',
                'linux_service': 'swift-object-auditor',
            }
        },
        'swift-object-replicator': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-object-replicator',
                'linux_service': 'swift-object-replicator',
            }
        },
        'swift-object-updater': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-object-updater',
                'linux_service': 'swift-object-updater',
            }
        },
        'swift-proxy': {
            'driver': 'linux_service',
            'args': {
                'grep': 'swift-proxy',
                'linux_service': 'swift-proxy',
            }
        },
    }
    SUPPORTED_NETWORKS = ['management', 'private', 'public', 'storage']
    CONFIG_SCHEMA = {
        'type': 'object',
        '$schema': 'http://json-schema.org/draft-04/schema#',
        'properties': {
            'address': {'type': 'string'},
            'username': {'type': 'string'},
            'private_key_file': {'type': 'string'},
            'slave_direct_ssh': {'type': 'boolean'},
            'serial': {'type': 'integer', 'minimum': 1},
        },
        'required': ['address', 'username'],
        'additionalProperties': False,
    }

    def __init__(self, cloud_management_params):
        super(FuelManagement, self).__init__()
        self.node_discover = self  # supports discovering

        self.master_node_address = cloud_management_params['address']
        self._master_host = node_collection.Host(ip=self.master_node_address)
        self.username = cloud_management_params['username']
        self.private_key_file = cloud_management_params.get('private_key_file')
        self.slave_direct_ssh = cloud_management_params.get(
            'slave_direct_ssh', False)
        self.serial = cloud_management_params.get('serial')

        self.master_node_executor = executor.AnsibleRunner(
            remote_user=self.username, private_key_file=self.private_key_file)

        jump_host = self.master_node_address
        if self.slave_direct_ssh:
            jump_host = None

        self.cloud_executor = executor.AnsibleRunner(
            remote_user=self.username, private_key_file=self.private_key_file,
            jump_host=jump_host, serial=self.serial)

        self.cached_cloud_hosts = list()

    def verify(self):
        """Verify connection to the cloud."""
        nodes = self.get_nodes()
        LOG.debug('Cloud nodes: %s', nodes)

        task = {'command': 'hostname'}
        task_result = self.execute_on_cloud(nodes.hosts, task)
        LOG.debug('Hostnames of cloud nodes: %s',
                  [r.payload['stdout'] for r in task_result])

        LOG.info('Connected to cloud successfully!')

    def discover_hosts(self):
        if not self.cached_cloud_hosts:
            task = {'command': 'fuel node --json'}
            result = self._execute_on_master_node(task)
            for r in json.loads(result[0].payload['stdout']):
                host = node_collection.Host(ip=r['ip'], mac=r['mac'],
                                            fqdn=r['fqdn'])
                self.cached_cloud_hosts.append(host)

        return self.cached_cloud_hosts

    def _execute_on_master_node(self, task):
        """Execute task on Fuel master node.

        :param task: Ansible task
        :return: Ansible execution result (list of records)
        """
        return self.master_node_executor.execute([self._master_host], task)

    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, [])