File: rcCloudOpenstack.py

package info (click to toggle)
opensvc 1.8~20170412-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 6,492 kB
  • ctags: 7,845
  • sloc: python: 77,169; sh: 339; xml: 39; makefile: 7
file content (71 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download
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
import rcCloud
import rcExceptions as ex
import socket

try:
    from libcloud.compute.types import Provider
    from libcloud.compute.providers import get_driver
    import libcloud.security
except ImportError:
    raise ex.excInitError("apache-libcloud module must be installed")

class Cloud(rcCloud.Cloud):
    mode = 'openstack'

    def __init__(self, s, auth):
        rcCloud.Cloud.__init__(self, s, auth)
        kwargs = {}

        if 'username' not in auth:
            raise ex.excInitError("option 'username' is mandatory in %s section"%self.mode)

        if 'password' not in auth:
            raise ex.excInitError("option 'password' is mandatory in %s section"%self.mode)

        if 'url' not in auth:
            raise ex.excInitError("option 'url' is mandatory in %s section"%self.mode)

        kwargs['ex_force_auth_url'] = auth['url']

        if 'tenant' in auth:
            self.tenant_name = auth['tenant']
            kwargs['ex_tenant_name'] = auth['tenant']
        else:
            self.tenant_name = None

        if 'version' in auth:
            kwargs['ex_force_auth_version'] = auth['version']
        else:
            kwargs['ex_force_auth_version'] = '2.0_password'

        if 'service_name' in auth:
            kwargs['ex_force_service_name'] = auth['service_name']

        if 'verify_ssl_cert' in auth and not auth['verify_ssl_cert']:
            libcloud.security.VERIFY_SSL_CERT = False

        openstack = get_driver(Provider.OPENSTACK)
        self.driver = openstack( auth['username'], auth['password'], **kwargs)

    def app_id(self, svcname=None):
        return self.tenant_name

    def cloud_id(self):
        return self.auth['url'].split("/")[2].split(':')[0]

    def app_cloud_id(self):
        _id = []
        app_id = self.app_id()
        if app_id is not None:
            _id.append(app_id)
        _id.append(self.cloud_id())
        return '.'.join(_id)

    def list_svcnames(self):
        l = []
        _id = self.app_cloud_id()
        for node in self.list_nodes():
            svcname = '.'.join((node.name, _id))
            l.append((node.name, svcname))
        return l