本文整理汇总了Python中kamaki.cli.config.Config.get方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get方法的具体用法?Python Config.get怎么用?Python Config.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kamaki.cli.config.Config
的用法示例。
在下文中一共展示了Config.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get [as 别名]
def test_get(self, get_cloud):
from kamaki.cli.config import Config
_cnf = Config(path=self.f.name)
self.assertEqual('pithos', _cnf.get('global', 'file_cli'))
self.assertEqual(get_cloud.mock_calls, [])
for opt, sec in (('cloud', 'non-existing'), ('non-opt', 'exists')):
self.assertEqual(None, _cnf.get(opt, sec))
self.assertEqual(get_cloud.mock_calls, [])
self.assertEqual('get cloud', _cnf.get('cloud.demo', 'url'))
self.assertEqual(get_cloud.mock_calls[-1], call('demo', 'url'))
示例2: get_config
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get [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
示例3: TORT
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get [as 别名]
# 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, 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 (
示例4: __init__
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get [as 别名]
class Provisioner:
"""
provisions virtual machines on ~okeanos
"""
def __init__(self, auth_token, cloud_name=None):
if auth_token is None and cloud_name is not None:
# Load .kamakirc configuration
logger.info("Retrieving .kamakirc configuration")
self.config = KamakiConfig()
patch_certs(self.config.get('global', 'ca_certs'))
cloud_section = self.config._sections['cloud'].get(cloud_name)
if not cloud_section:
message = "Cloud '%s' was not found in you .kamakirc configuration file. " \
"Currently you have availablie in your configuration these clouds: %s"
raise KeyError(message % (cloud_name, self.config._sections['cloud'].keys()))
# Get the authentication url and token
auth_url, auth_token = cloud_section['url'], cloud_section['token']
else:
auth_url = "https://accounts.okeanos.grnet.gr/identity/v2.0"
logger.info("Initiating Astakos Client")
self.astakos = astakos.AstakosClient(auth_url, auth_token)
logger.info("Retrieving cyclades endpoint url")
compute_url = self.astakos.get_endpoint_url(
cyclades.CycladesComputeClient.service_type)
logger.info("Initiating Cyclades client")
self.cyclades = cyclades.CycladesComputeClient(compute_url, auth_token)
# Create the network client
networkURL = self.astakos.get_endpoint_url(
cyclades.CycladesNetworkClient.service_type)
self.network_client = cyclades.CycladesNetworkClient(networkURL, auth_token)
# Constants
self.Bytes_to_GB = 1024 * 1024 * 1024
self.Bytes_to_MB = 1024 * 1024
self.master = None
self.ips = None
self.slaves = None
self.vpn = None
self.subnet = None
self.private_key = None
self.image_id = 'c6f5adce-21ad-4ce3-8591-acfe7eb73c02'
"""
FIND RESOURCES
"""
def find_flavor(self, **kwargs):
"""
:param kwargs: should contains the keys that specify the specs
:return: first flavor objects that matches the specs criteria
"""
# Set all the default parameters
kwargs.setdefault("vcpus", 1)
kwargs.setdefault("ram", 1024)
kwargs.setdefault("disk", 40)
kwargs.setdefault("SNF:allow_create", True)
logger.info("Retrieving flavor")
for flavor in self.cyclades.list_flavors(detail=True):
if all([kwargs[key] == flavor[key]
for key in set(flavor.keys()).intersection(kwargs.keys())]):
return flavor
return None
def find_image(self, **kwargs):
"""
:param image_name: Name of the image to filter by
:param kwargs:
:return: first image object that matches the name criteria
"""
image_name = kwargs['image_name']
logger.info("Retrieving image")
for image in self.cyclades.list_images(detail=True):
if image_name in image['name']:
return image
return None
def find_project_id(self, **kwargs):
"""
:param kwargs: name, state, owner and mode to filter project by
:return: first project_id that matches the project name
"""
filter = {
'name': kwargs.get("project_name"),
'state': kwargs.get("project_state"),
'owner': kwargs.get("project_owner"),
'mode': kwargs.get("project_mode"),
}
logger.info("Retrieving project")
#.........这里部分代码省略.........
示例5: TORT
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import get [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"])