本文整理汇总了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'])