~cprov/charms/trusty/adt-cloud-worker/py2-production

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/amulet/deployment.py

  • Committer: Paul Larson
  • Date: 2015-03-04 14:54:10 UTC
  • Revision ID: paul.larson@canonical.com-20150304145410-t8lexkpisk2kz308
start working on adt-cloud-worker

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014-2015 Canonical Limited.
 
2
#
 
3
# This file is part of charm-helpers.
 
4
#
 
5
# charm-helpers is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License version 3 as
 
7
# published by the Free Software Foundation.
 
8
#
 
9
# charm-helpers is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public License
 
15
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
import six
 
18
from charmhelpers.contrib.amulet.deployment import (
 
19
    AmuletDeployment
 
20
)
 
21
 
 
22
 
 
23
class OpenStackAmuletDeployment(AmuletDeployment):
 
24
    """OpenStack amulet deployment.
 
25
 
 
26
       This class inherits from AmuletDeployment and has additional support
 
27
       that is specifically for use by OpenStack charms.
 
28
       """
 
29
 
 
30
    def __init__(self, series=None, openstack=None, source=None, stable=True):
 
31
        """Initialize the deployment environment."""
 
32
        super(OpenStackAmuletDeployment, self).__init__(series)
 
33
        self.openstack = openstack
 
34
        self.source = source
 
35
        self.stable = stable
 
36
        # Note(coreycb): this needs to be changed when new next branches come
 
37
        # out.
 
38
        self.current_next = "trusty"
 
39
 
 
40
    def _determine_branch_locations(self, other_services):
 
41
        """Determine the branch locations for the other services.
 
42
 
 
43
           Determine if the local branch being tested is derived from its
 
44
           stable or next (dev) branch, and based on this, use the corresonding
 
45
           stable or next branches for the other_services."""
 
46
        base_charms = ['mysql', 'mongodb', 'rabbitmq-server']
 
47
 
 
48
        if self.stable:
 
49
            for svc in other_services:
 
50
                temp = 'lp:charms/{}'
 
51
                svc['location'] = temp.format(svc['name'])
 
52
        else:
 
53
            for svc in other_services:
 
54
                if svc['name'] in base_charms:
 
55
                    temp = 'lp:charms/{}'
 
56
                    svc['location'] = temp.format(svc['name'])
 
57
                else:
 
58
                    temp = 'lp:~openstack-charmers/charms/{}/{}/next'
 
59
                    svc['location'] = temp.format(self.current_next,
 
60
                                                  svc['name'])
 
61
        return other_services
 
62
 
 
63
    def _add_services(self, this_service, other_services):
 
64
        """Add services to the deployment and set openstack-origin/source."""
 
65
        other_services = self._determine_branch_locations(other_services)
 
66
 
 
67
        super(OpenStackAmuletDeployment, self)._add_services(this_service,
 
68
                                                             other_services)
 
69
 
 
70
        services = other_services
 
71
        services.append(this_service)
 
72
        use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph',
 
73
                      'ceph-osd', 'ceph-radosgw']
 
74
 
 
75
        if self.openstack:
 
76
            for svc in services:
 
77
                if svc['name'] not in use_source:
 
78
                    config = {'openstack-origin': self.openstack}
 
79
                    self.d.configure(svc['name'], config)
 
80
 
 
81
        if self.source:
 
82
            for svc in services:
 
83
                if svc['name'] in use_source:
 
84
                    config = {'source': self.source}
 
85
                    self.d.configure(svc['name'], config)
 
86
 
 
87
    def _configure_services(self, configs):
 
88
        """Configure all of the services."""
 
89
        for service, config in six.iteritems(configs):
 
90
            self.d.configure(service, config)
 
91
 
 
92
    def _get_openstack_release(self):
 
93
        """Get openstack release.
 
94
 
 
95
           Return an integer representing the enum value of the openstack
 
96
           release.
 
97
           """
 
98
        (self.precise_essex, self.precise_folsom, self.precise_grizzly,
 
99
         self.precise_havana, self.precise_icehouse,
 
100
         self.trusty_icehouse) = range(6)
 
101
        releases = {
 
102
            ('precise', None): self.precise_essex,
 
103
            ('precise', 'cloud:precise-folsom'): self.precise_folsom,
 
104
            ('precise', 'cloud:precise-grizzly'): self.precise_grizzly,
 
105
            ('precise', 'cloud:precise-havana'): self.precise_havana,
 
106
            ('precise', 'cloud:precise-icehouse'): self.precise_icehouse,
 
107
            ('trusty', None): self.trusty_icehouse}
 
108
        return releases[(self.series, self.openstack)]