~niedbalski/ubuntu/vivid/neutron/fixes-1447803

« back to all changes in this revision

Viewing changes to neutron/plugins/ml2/drivers/arista/mechanism_arista.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-10-03 18:45:23 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20141003184523-4mt6dy1q3j8n30c9
Tags: 1:2014.2~rc1-0ubuntu1
* New upstream release candidate:
  - d/p/*: Refreshed.
  - d/control: Add python-requests-mock to BD's.
  - d/control: Align versioned requirements with upstream.
* Transition linuxbridge and openvswitch plugin users to modular
  layer 2 plugin (LP: #1323729):
  - d/control: Mark removed plugin packages as transitional, depend
    on neutron-plugin-ml2, mark oldlibs/extra.
  - d/neutron-plugin-{linuxbridge,openvswitch}.install: Drop.
  - d/control: Depend on neutron-plugin-ml2 for linuxbridge
    agent package.
  - d/neutron-plugin-linuxbridge-agent.upstart: Use ml2 plugin
    configuration files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
 
 
16
import itertools
16
17
import threading
17
18
 
18
19
import jsonrpclib
43
44
        self._server = jsonrpclib.Server(self._eapi_host_url())
44
45
        self.keystone_conf = cfg.CONF.keystone_authtoken
45
46
        self.region = cfg.CONF.ml2_arista.region_name
 
47
        self.sync_interval = cfg.CONF.ml2_arista.sync_interval
46
48
        self._region_updated_time = None
47
49
        # The cli_commands dict stores the mapping between the CLI command key
48
50
        # and the actual CLI command.
198
200
                'exit']
199
201
        self._run_openstack_cmds(cmds)
200
202
 
 
203
    def sync_start(self):
 
204
        """Sends indication to EOS that ML2->EOS sync has started."""
 
205
 
 
206
        sync_start_cmd = ['sync start']
 
207
        self._run_openstack_cmds(sync_start_cmd)
 
208
 
 
209
    def sync_end(self):
 
210
        """Sends indication to EOS that ML2->EOS sync has completed."""
 
211
 
 
212
        sync_end_cmd = ['sync end']
 
213
        self._run_openstack_cmds(sync_end_cmd)
 
214
 
201
215
    def create_network(self, tenant_id, network):
202
216
        """Creates a single network on Arista hardware
203
217
 
377
391
        This the initial handshake between Neutron and EOS.
378
392
        critical end-point information is registered with EOS.
379
393
        """
380
 
        cmds = ['auth url %s user "%s" password "%s"' %
381
 
                (self._keystone_url(),
 
394
 
 
395
        cmds = ['auth url %s user %s password %s tenant %s' % (
 
396
                self._keystone_url(),
382
397
                self.keystone_conf.admin_user,
383
 
                self.keystone_conf.admin_password)]
384
 
 
385
 
        log_cmds = ['auth url %s user %s password ******' %
386
 
                    (self._keystone_url(),
387
 
                    self.keystone_conf.admin_user)]
 
398
                self.keystone_conf.admin_password,
 
399
                self.keystone_conf.admin_tenant_name)]
 
400
 
 
401
        log_cmds = ['auth url %s user %s password %s tenant %s' % (
 
402
                    self._keystone_url(),
 
403
                    self.keystone_conf.admin_user,
 
404
                    '******',
 
405
                    self.keystone_conf.admin_tenant_name)]
 
406
 
 
407
        sync_interval_cmd = 'sync interval %d' % self.sync_interval
 
408
        cmds.append(sync_interval_cmd)
 
409
        log_cmds.append(sync_interval_cmd)
388
410
 
389
411
        self._run_openstack_cmds(cmds, commands_to_log=log_cmds)
390
412
 
424
446
                                 param is logged.
425
447
        """
426
448
 
427
 
        log_cmd = commands
 
449
        log_cmds = commands
428
450
        if commands_to_log:
429
 
            log_cmd = commands_to_log
 
451
            log_cmds = commands_to_log
430
452
 
431
 
        LOG.info(_('Executing command on Arista EOS: %s'), log_cmd)
 
453
        LOG.info(_('Executing command on Arista EOS: %s'), log_cmds)
432
454
 
433
455
        try:
434
456
            # this returns array of return values for every command in
436
458
            ret = self._server.runCmds(version=1, cmds=commands)
437
459
        except Exception as error:
438
460
            host = cfg.CONF.ml2_arista.eapi_host
 
461
            error_msg_str = unicode(error)
 
462
            if commands_to_log:
 
463
                # The command might contain sensitive information. If the
 
464
                # command to log is different from the actual command, use
 
465
                # that in the error message.
 
466
                for cmd, log_cmd in itertools.izip(commands, log_cmds):
 
467
                    error_msg_str = error_msg_str.replace(cmd, log_cmd)
439
468
            msg = (_('Error %(err)s while trying to execute '
440
469
                     'commands %(cmd)s on EOS %(host)s') %
441
 
                   {'err': error, 'cmd': commands_to_log, 'host': host})
442
 
            LOG.exception(msg)
 
470
                  {'err': error_msg_str,
 
471
                   'cmd': commands_to_log,
 
472
                   'host': host})
 
473
            # Logging exception here can reveal passwords as the exception
 
474
            # contains the CLI command which contains the credentials.
 
475
            LOG.error(msg)
443
476
            raise arista_exc.AristaRpcError(msg=msg)
444
477
 
445
478
        return ret
514
547
 
515
548
 
516
549
class SyncService(object):
517
 
    """Synchronizatin of information between Neutron and EOS
 
550
    """Synchronization of information between Neutron and EOS
518
551
 
519
552
    Periodically (through configuration option), this service
520
553
    ensures that Networks and VMs configured on EOS/Arista HW
525
558
        self._ndb = neutron_db
526
559
        self._force_sync = True
527
560
 
 
561
    def do_synchronize(self):
 
562
        try:
 
563
            # Send trigger to EOS that the ML2->EOS sync has started.
 
564
            self._rpc.sync_start()
 
565
            LOG.info(_('Sync start trigger sent to EOS'))
 
566
        except arista_exc.AristaRpcError:
 
567
            LOG.warning(EOS_UNREACHABLE_MSG)
 
568
            return
 
569
 
 
570
        # Perform the sync
 
571
        self.synchronize()
 
572
 
 
573
        try:
 
574
            # Send trigger to EOS that the ML2->EOS sync is Complete.
 
575
            self._rpc.sync_end()
 
576
        except arista_exc.AristaRpcError:
 
577
            LOG.warning(EOS_UNREACHABLE_MSG)
 
578
 
528
579
    def synchronize(self):
529
580
        """Sends data to EOS which differs from neutron DB."""
530
581
 
991
1042
 
992
1043
    def _synchronization_thread(self):
993
1044
        with self.eos_sync_lock:
994
 
            self.eos.synchronize()
 
1045
            self.eos.do_synchronize()
995
1046
 
996
1047
        self.timer = threading.Timer(self.sync_timeout,
997
1048
                                     self._synchronization_thread)