~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/plugins/vmware/nsx_cluster.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012 VMware, Inc.
2
 
# All Rights Reserved
3
 
#
4
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
 
#    not use this file except in compliance with the License. You may obtain
6
 
#    a copy of the License at
7
 
#
8
 
#         http://www.apache.org/licenses/LICENSE-2.0
9
 
#
10
 
#    Unless required by applicable law or agreed to in writing, software
11
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 
#    License for the specific language governing permissions and limitations
14
 
#    under the License.
15
 
 
16
 
from oslo.config import cfg
17
 
 
18
 
from neutron.i18n import _LI
19
 
from neutron.openstack.common import log as logging
20
 
from neutron.plugins.vmware.common import exceptions
21
 
 
22
 
LOG = logging.getLogger(__name__)
23
 
DEFAULT_PORT = 443
24
 
# Raise if one of those attributes is not specified
25
 
REQUIRED_ATTRIBUTES = ['default_tz_uuid', 'nsx_user',
26
 
                       'nsx_password', 'nsx_controllers']
27
 
# Emit a INFO log if one of those attributes is not specified
28
 
IMPORTANT_ATTRIBUTES = ['default_l3_gw_service_uuid']
29
 
# Deprecated attributes
30
 
DEPRECATED_ATTRIBUTES = ['metadata_dhcp_host_route',
31
 
                         'nvp_user', 'nvp_password', 'nvp_controllers']
32
 
 
33
 
 
34
 
class NSXCluster(object):
35
 
    """NSX cluster class.
36
 
 
37
 
    Encapsulates controller connections and the API client for a NSX cluster.
38
 
 
39
 
    Controller-specific parameters, such as timeouts are stored in the
40
 
    elements of the controllers attribute, which are dicts.
41
 
    """
42
 
 
43
 
    def __init__(self, **kwargs):
44
 
        self._required_attributes = REQUIRED_ATTRIBUTES[:]
45
 
        self._important_attributes = IMPORTANT_ATTRIBUTES[:]
46
 
        self._deprecated_attributes = {}
47
 
        self._sanity_check(kwargs)
48
 
 
49
 
        for opt, val in self._deprecated_attributes.iteritems():
50
 
            LOG.deprecated(_("Attribute '%s' has been deprecated or moved "
51
 
                             "to a new section. See new configuration file "
52
 
                             "for details."), opt)
53
 
            depr_func = getattr(self, '_process_%s' % opt, None)
54
 
            if depr_func:
55
 
                depr_func(val)
56
 
 
57
 
        # If everything went according to plan these two lists should be empty
58
 
        if self._required_attributes:
59
 
            raise exceptions.InvalidClusterConfiguration(
60
 
                invalid_attrs=self._required_attributes)
61
 
        if self._important_attributes:
62
 
            LOG.info(_LI("The following cluster attributes were "
63
 
                         "not specified: %s'"), self._important_attributes)
64
 
        # The API client will be explicitly created by users of this class
65
 
        self.api_client = None
66
 
 
67
 
    def _sanity_check(self, options):
68
 
        # Iterating this way ensures the conf parameters also
69
 
        # define the structure of this class
70
 
        for arg in cfg.CONF:
71
 
            if arg not in DEPRECATED_ATTRIBUTES:
72
 
                setattr(self, arg, options.get(arg, cfg.CONF.get(arg)))
73
 
                self._process_attribute(arg)
74
 
            elif options.get(arg) is not None:
75
 
                # Process deprecated attributes only if specified
76
 
                self._deprecated_attributes[arg] = options.get(arg)
77
 
 
78
 
    def _process_attribute(self, attribute):
79
 
        # Process the attribute only if it's not empty!
80
 
        if getattr(self, attribute, None):
81
 
            if attribute in self._required_attributes:
82
 
                self._required_attributes.remove(attribute)
83
 
            if attribute in self._important_attributes:
84
 
                self._important_attributes.remove(attribute)
85
 
            handler_func = getattr(self, '_process_%s' % attribute, None)
86
 
            if handler_func:
87
 
                handler_func()
88
 
 
89
 
    def _process_nsx_controllers(self):
90
 
        # If this raises something is not right, so let it bubble up
91
 
        # TODO(salvatore-orlando): Also validate attribute here
92
 
        for i, ctrl in enumerate(self.nsx_controllers or []):
93
 
            if len(ctrl.split(':')) == 1:
94
 
                self.nsx_controllers[i] = '%s:%s' % (ctrl, DEFAULT_PORT)
95
 
 
96
 
    def _process_nvp_controllers(self):
97
 
        self.nsx_controllers = self.nvp_controllers
98
 
        self._process_nsx_controllers()