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


Python InfrastructureManager.attach_disk方法代码示例

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


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

示例1: test_attach_persistent_disk

# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import attach_disk [as 别名]
  def test_attach_persistent_disk(self):
    # mock out interactions with GCE
    # first, mock out the oauth library calls
    fake_credentials = flexmock(name='fake_credentials', invalid=False)
    fake_storage = flexmock(name='fake_storage')
    fake_storage.should_receive('get').and_return(fake_credentials)

    flexmock(oauth2client.file)
    oauth2client.file.should_receive('Storage').with_args(
      GCEAgent.OAUTH2_STORAGE_LOCATION).and_return(fake_storage)

    # next, mock out http calls to GCE
    fake_http = flexmock(name='fake_http')
    fake_authorized_http = flexmock(name='fake_authorized_http')

    flexmock(httplib2)
    httplib2.should_receive('Http').and_return(fake_http)
    fake_credentials.should_receive('authorize').with_args(fake_http) \
      .and_return(fake_authorized_http)

    fake_instances = flexmock(name='fake_instances')
    fake_gce = flexmock(name='fake_gce')
    fake_gce.should_receive('instances').and_return(fake_instances)

    fake_attach_disk_request = flexmock(name='fake_attach_disk_request')
    fake_instances.should_receive('get').and_return(fake_attach_disk_request)

    attach_disk_info = {
      'status': 'DONE',
      'disks': []
    }

    fake_attach_disk_request.should_receive('execute').with_args(
      fake_authorized_http).and_return(attach_disk_info)

    fake_instances.should_receive('attachDisk').with_args(project=self.project,
      body=dict, instance='my-instance', zone=str).and_return(
      fake_attach_disk_request)

    # finally, inject our fake GCE connection
    flexmock(discovery)
    discovery.should_receive('build').with_args('compute',
      GCEAgent.API_VERSION).and_return(fake_gce)

    iaas = InfrastructureManager(blocking=True)
    disk_name = 'my-disk-name'
    instance_id = 'my-instance'
    expected = '/dev/sdb'
    actual = iaas.attach_disk(self.params, disk_name, instance_id, 'secret')
    self.assertTrue(actual['success'])
    self.assertEquals(expected, actual['location'])
开发者ID:tmarballi,项目名称:appscale,代码行数:53,代码来源:test_gce_agent.py


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