當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。