当前位置: 首页>>代码示例>>Python>>正文


Python Config.get_cloud方法代码示例

本文整理汇总了Python中kamaki.cli.config.Config.get_cloud方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get_cloud方法的具体用法?Python Config.get_cloud怎么用?Python Config.get_cloud使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kamaki.cli.config.Config的用法示例。


在下文中一共展示了Config.get_cloud方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_config

# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get_cloud [as 别名]
    def get_config(cls):
        okeanos_ssh_key_path = os.environ.get('OKEANOS_SSH_KEY')
        if not okeanos_ssh_key_path:
            raise ConfigError("Please set the OKEANOS_SSH_KEY with the path to your public ssh key")

        kamakirc_path = os.environ.get('OKEANOS_KAMAKIRC')
        okeanos_config = Config(kamakirc_path)

        # This is debian specific... for now...
        okeanos_config.set('global', 'ca_certs', '/etc/ssl/certs/ca-certificates.crt')
        cloud_name = okeanos_config.get('global', 'default_cloud')
        auth_url = okeanos_config.get_cloud(cloud_name, 'url')
        auth_token = okeanos_config.get_cloud(cloud_name, 'token')

        if (not cloud_name or not auth_url or not auth_token):
            raise ConfigError("Wrong okeanos configuration")
        return okeanos_config
开发者ID:ktsakalozos,项目名称:juju-okeanos-provider,代码行数:19,代码来源:provider.py

示例2: test_get_cloud

# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get_cloud [as 别名]
    def test_get_cloud(self):
        from kamaki.cli.config import Config, CLOUD_PREFIX

        _cnf = Config(path=self.f.name)
        d = dict(opt1='v1', opt2='v2')
        with patch('kamaki.cli.config.Config.get', return_value=d) as get:
            self.assertEqual('v1', _cnf.get_cloud('mycloud', 'opt1'))
            self.assertEqual(
                get.mock_calls[-1], call(CLOUD_PREFIX, 'mycloud'))
            self.assertRaises(KeyError, _cnf.get_cloud, 'mycloud', 'opt3')
        with patch('kamaki.cli.config.Config.get', return_value=0) as get:
            self.assertRaises(KeyError, _cnf.get_cloud, 'mycloud', 'opt1')
开发者ID:Erethon,项目名称:kamaki,代码行数:14,代码来源:test.py

示例3: Config

# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get_cloud [as 别名]
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.cli.config import Config
from kamaki.clients import astakos, cyclades, ClientError
from kamaki.clients.utils import https

https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt')
cnf = Config()
CLOUD = cnf.get('global', 'default_cloud')
URL = cnf.get_cloud(CLOUD, 'url')
TOKEN = cnf.get_cloud(CLOUD, 'token')
identity_client = astakos.CachedAstakosClient(URL, TOKEN)

computeURL = identity_client.get_endpoint_url(
    cyclades.CycladesComputeClient.service_type)
compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN)

volumeURL = identity_client.get_endpoint_url(
    cyclades.CycladesBlockStorageClient.service_type)
volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN)

srv = compute_client.get_server_details(454001)

snapshots = [snp for snp in volume_client.list_snapshots(detail=True) if (
    snp['volume_id'] == srv['volumes'][0])]
开发者ID:loverdos,项目名称:kamaki,代码行数:33,代码来源:025_lookup_snapshot.py

示例4: test_rescue_old_file

# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get_cloud [as 别名]
    def test_rescue_old_file(self):
        from kamaki.cli.config import Config

        content0 = list(self.config_file_content)

        def make_file(lines):
            f = NamedTemporaryFile()
            f.writelines(lines)
            f.flush()
            return f

        with make_file(content0) as f:
            _cnf = Config(path=f.name)
            self.assertEqual([], _cnf.rescue_old_file())
        del _cnf

        content1, sample = list(content0), 'xyz_cli = XYZ_specs'
        content1.insert(2, '%s\n' % sample)

        with make_file(content1) as f:
            f.seek(0)
            _cnf = Config(path=f.name)
            self.assertEqual(
                sorted(['global.%s' % sample]), sorted(_cnf.rescue_old_file()))
        del _cnf

        content2, sample = list(content0), 'http://www.example2.org'
        content2.insert(2, 'url = %s\n' % sample)
        err = StringIO()

        with make_file(content2) as f:
            _cnf = Config(path=f.name)
            self.assertEqual([], _cnf.rescue_old_file(err=err))
            self.assertEqual(
                '... rescue global.url => cloud.default.url\n', err.getvalue())
            self.assertEqual(sample, _cnf.get_cloud('default', 'url'))
        del _cnf

        content3 = list(content0)
        content3.insert(
            2, 'url = http://example1.com\nurl = http://example2.com\n')

        with make_file(content3) as f:
            _cnf = Config(path=f.name)
            self.assertEqual([], _cnf.rescue_old_file(err=err))
            self.assertEqual(
                2 * '... rescue global.url => cloud.default.url\n',
                err.getvalue())
            self.assertEqual(
                'http://example2.com', _cnf.get_cloud('default', 'url'))
        del _cnf

        content4 = list(content0)
        content4.insert(2, 'url = http://example1.com\n')
        content4.append('\n[cloud "default"]\nurl=http://example2.com\n')

        with make_file(content4) as f:
            _cnf = Config(path=f.name)
            from kamaki.cli.errors import CLISyntaxError
            self.assertRaises(CLISyntaxError, _cnf.rescue_old_file)
        del _cnf

        content5 = list(content0)
        extras = [
            ('pithos_cli', 'pithos'), ('store_cli', 'pithos'),
            ('storage_cli', 'pithos'), ('compute_cli', 'cyclades'),
            ('cyclades_cli', 'cyclades')]
        for sample in extras:
            content5.insert(2, '%s = %s\n' % sample)

        with make_file(content5) as f:
            _cnf = Config(path=f.name)
            self.assertEqual(
                sorted(['global.%s = %s' % sample for sample in extras]),
                 sorted(_cnf.rescue_old_file()))
开发者ID:Erethon,项目名称:kamaki,代码行数:77,代码来源:test.py

示例5: TORT

# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get_cloud [as 别名]
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.cli.config import Config
from kamaki.clients import astakos, image, ClientError
from kamaki.clients.utils import https

https.patch_with_certs("/etc/ssl/certs/ca-certificates.crt")
cnf = Config()
CLOUD = cnf.get("global", "default_cloud")
URL = cnf.get_cloud(CLOUD, "url")
TOKEN = cnf.get_cloud(CLOUD, "token")
identity_client = astakos.CachedAstakosClient(URL, TOKEN)

imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type)
image_client = image.ImageClient(imageURL, TOKEN)

location = (identity_client.user_info()["id"], "images", "my_image.diskdump")
properties = dict(osfamily="linux", users="root", os="debian")
img = image_client.register("My New Image", location, properties=properties)

image_client.unregister(img["id"])
开发者ID:skalkoto,项目名称:kamaki,代码行数:32,代码来源:012_unregister_image.py


注:本文中的kamaki.cli.config.Config.get_cloud方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。