~ibmcharmers/charms/trusty/ibm-glance-spectrumscale/trunk

« back to all changes in this revision

Viewing changes to hooks/cinder_contexts.py

  • Committer: Suchitra Venugopal
  • Date: 2017-01-27 11:21:55 UTC
  • Revision ID: suchvenu@in.ibm.com-20170127112155-crrgnwmavhqnu93n
IBM Glance SpectrumScale charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2016 Canonical Ltd
2
 
#
3
 
# Licensed under the Apache License, Version 2.0 (the "License");
4
 
# you may not use this file except in compliance with the License.
5
 
# You may obtain a copy of the License at
6
 
#
7
 
#  http://www.apache.org/licenses/LICENSE-2.0
8
 
#
9
 
# Unless required by applicable law or agreed to in writing, software
10
 
# distributed under the License is distributed on an "AS IS" BASIS,
11
 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
# See the License for the specific language governing permissions and
13
 
# limitations under the License.
14
 
 
15
 
from charmhelpers.core.hookenv import (
16
 
    service_name,
17
 
)
18
 
 
19
 
from charmhelpers.contrib.openstack.context import (
20
 
    OSContextGenerator,
21
 
)
22
 
 
23
 
 
24
 
class SpectrumScaleSubordinateContext(OSContextGenerator):
25
 
    interfaces = ['spectrumscale-cinder']
26
 
 
27
 
    def __call__(self, data=None):
28
 
        """
29
 
        Used to generate template context to be added to cinder.conf in the
30
 
        presence of a ceph relation.
31
 
        """
32
 
        service = service_name()
33
 
        print("Each values printing")
34
 
        print(data["volume-driver"])
35
 
        print(data["gpfs-login"])
36
 
        print(data["gpfs-ssh-port"])
37
 
 
38
 
        volume_driver = data["volume-driver"]
39
 
        gpfs_mount = data["gpfs_mount_point_base"]
40
 
        gpfs_sparse_vol = data["gpfs_sparse_volumes"]
41
 
 
42
 
        gpfs_storage_pool = data["gpfs_storage_pool"]
43
 
        gpfs_login = data["gpfs-login"]
44
 
        gpfs_private_key = data["gpfs_private_key"]
45
 
        gpfs_ssh_port = data["gpfs-ssh-port"]
46
 
        gpfs_images_dir = data["gpfs_images_dir"]
47
 
        gpfs_img_shr_mode = data["gpfs_images_share_mode"]
48
 
        volume_backend_name = 'GPFS'
49
 
        ipstr = self.concatenate_ips()
50
 
        values_to_add = [('volume_driver', volume_driver),
51
 
                         ('gpfs_mount_point_base', gpfs_mount),
52
 
                         ('gpfs_sparse_volumes', gpfs_sparse_vol),
53
 
                         ('gpfs_storage_pool', gpfs_storage_pool),
54
 
                         ('gpfs_hosts', ipstr),
55
 
                         ('gpfs_user_login', gpfs_login),
56
 
                         ('gpfs_private_key', gpfs_private_key),
57
 
                         ('gpfs_ssh_port', gpfs_ssh_port),
58
 
                         ('volume_backend_name', volume_backend_name),
59
 
                         ]
60
 
 
61
 
        if str(gpfs_images_dir) != 'None' \
62
 
                and str(gpfs_images_dir) != '':
63
 
            values_to_add.append(['gpfs_images_dir', gpfs_images_dir])
64
 
        if str(gpfs_img_shr_mode) != 'None' \
65
 
                and str(gpfs_img_shr_mode) != '':
66
 
            values_to_add.append(['gpfs_images_share_mode', gpfs_img_shr_mode])
67
 
 
68
 
        return {
69
 
            "cinder": {
70
 
                "/etc/cinder/cinder.conf": {
71
 
                    "sections": {
72
 
                        service: values_to_add
73
 
                    }
74
 
                }
75
 
            }
76
 
        }
77
 
 
78
 
    def concatenate_ips(self):
79
 
        ipfilename = './client_ips.txt'
80
 
        ipfile = open(ipfilename, "r+")
81
 
        ipstr = ''
82
 
        d = ipfile.readlines()
83
 
        for i in d:
84
 
            ipstr = ipstr+i.strip()+','
85
 
        ipstr = ipstr[:-1]
86
 
        print("Final list of IPs is %s" % ipstr)
87
 
        return ipstr