~ubuntu-branches/ubuntu/vivid/sahara/vivid-proposed

« back to all changes in this revision

Viewing changes to sahara/swift/swift_helper.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-8gu3zscu5e3n9lr2
Tags: upstream-2014.2~b3
ImportĀ upstreamĀ versionĀ 2014.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2013 Mirantis Inc.
 
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
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
 
 
16
import logging
 
17
 
 
18
from oslo.config import cfg
 
19
 
 
20
from sahara import context
 
21
from sahara.i18n import _LI
 
22
from sahara.swift import utils as su
 
23
from sahara.utils import xmlutils as x
 
24
 
 
25
 
 
26
LOG = logging.getLogger(__name__)
 
27
CONF = cfg.CONF
 
28
HADOOP_SWIFT_AUTH_URL = 'fs.swift.service.sahara.auth.url'
 
29
HADOOP_SWIFT_TENANT = 'fs.swift.service.sahara.tenant'
 
30
HADOOP_SWIFT_USERNAME = 'fs.swift.service.sahara.username'
 
31
HADOOP_SWIFT_PASSWORD = 'fs.swift.service.sahara.password'
 
32
HADOOP_SWIFT_REGION = 'fs.swift.service.sahara.region'
 
33
 
 
34
 
 
35
def retrieve_tenant():
 
36
    return context.current().tenant_name
 
37
 
 
38
 
 
39
def get_swift_configs():
 
40
    configs = x.load_hadoop_xml_defaults('swift/resources/conf-template.xml')
 
41
    for conf in configs:
 
42
        if conf['name'] == HADOOP_SWIFT_AUTH_URL:
 
43
            conf['value'] = su.retrieve_auth_url() + "tokens/"
 
44
        if conf['name'] == HADOOP_SWIFT_TENANT:
 
45
            conf['value'] = retrieve_tenant()
 
46
        if CONF.os_region_name and conf['name'] == HADOOP_SWIFT_REGION:
 
47
            conf['value'] = CONF.os_region_name
 
48
 
 
49
    result = [cfg for cfg in configs if cfg['value']]
 
50
    LOG.info(_LI("Swift would be integrated with the following "
 
51
             "params: %s"), result)
 
52
    return result