本文整理汇总了Python中gns3.cloud.rackspace_ctrl.RackspaceCtrl.set_region方法的典型用法代码示例。如果您正苦于以下问题:Python RackspaceCtrl.set_region方法的具体用法?Python RackspaceCtrl.set_region怎么用?Python RackspaceCtrl.set_region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gns3.cloud.rackspace_ctrl.RackspaceCtrl
的用法示例。
在下文中一共展示了RackspaceCtrl.set_region方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_region
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
def test_set_region(self):
""" Ensure that set_region sets 'region' and 'driver'. """
ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
ctrl.authenticate()
result = ctrl.set_region('iad')
self.assertEqual(result, True)
self.assertEqual(ctrl.region, 'iad')
self.assertIsNotNone(ctrl.driver)
示例2: TestRackspaceCtrlDriver
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrlDriver(unittest.TestCase):
""" Test the libcloud Rackspace driver. """
class StubObject(object):
def __init__(self, **kwargs):
for arg in kwargs:
setattr(self, arg, kwargs[arg])
def setUp(self):
""" Set up the objects used by most of the tests. """
self.ctrl = RackspaceCtrl('valid_user', 'valid_api_key', 'http://foo.bar:8888')
self.ctrl.post_fn = stub_rackspace_identity_post
self.ctrl.driver_cls = MockLibCloudDriver
self.ctrl.authenticate()
self.ctrl.set_region('iad')
self.ctrl.get_image = mock.MagicMock()
self.ctrl.get_image.return_value = ''
self.key_pair = TestRackspaceCtrlDriver.StubObject(public_key='keystr')
def test_create_instance_over_limit(self):
""" Ensure '413 Over Limit' error is handled properly. """
self.assertRaises(OverLimit, self.ctrl.create_instance,
'over_limit', 'size', 'image', self.key_pair)
def test_create_instance_bad_request(self):
""" Ensure '400 Bad Request' error is handled properly. """
self.assertRaises(BadRequest, self.ctrl.create_instance,
'bad_request', 'size', 'image', self.key_pair)
def test_delete_instance_nonexistant(self):
""" Ensure '404 Instance not found' error is handled properly. """
instance = TestRackspaceCtrlDriver.StubObject(name='nonexistant')
self.assertRaises(ItemNotFound, self.ctrl.delete_instance,
instance)
def test_create_key_pair_duplicate_name(self):
""" Ensure '409 Key Pair exists' error is handled properly. """
self.assertRaises(KeyPairExists, self.ctrl.create_key_pair,
'duplicate_name')
def test_service_uavailable(self):
""" Ensure '503 Service Unavailable' error is handled properly. """
self.assertRaises(ServiceUnavailable, self.ctrl.create_instance,
'service_unavailable', 'size', 'image',
self.key_pair)
def test_unauthorized(self):
""" Ensure '401 Unauthroized' error is handled properly. """
self.assertRaises(Unauthorized, self.ctrl.create_instance,
'unauthorized', 'size', 'image', self.key_pair)
def test_api_error(self):
""" Ensure '500 ...' error is handled properly. """
self.assertRaises(ApiError, self.ctrl.create_instance, 'api_error',
'size', 'image', self.key_pair)
def test_list_images(self):
self.ctrl.tenant_id = '1234567890'
self.ctrl._get_shared_images = mock.MagicMock()
self.ctrl._get_shared_images.return_value = [
{
"image_name": "foo",
"schema": "/v2/schemas/member",
"status": "pending",
"image_id": "1c6ba38d-5960-4cc1-a3db-bab521e99afa",
"member_id": "user_foo",
"created_at": "2014-06-25T13:49:56Z",
"updated_at": "2014-06-25T13:49:56Z"
},
{
"image_name": "foo2",
"schema": "/v2/schemas/member",
"status": "pending",
"image_id": "a44a6c31-a437-498e-b4e4-3a6cb9d1d733",
"member_id": "user_foo",
"created_at": "2014-06-25T13:49:59Z",
"updated_at": "2014-06-25T13:49:59Z"
},
{
"image_name": "foo3",
"member_id": "user_foo",
"image_id": "64c3b6e5-05c1-4407-82b9-5690cdfaa887",
"status": "ALREADYREQUESTED"
},
{
"image_name": "foo4",
"member_id": "user_foo",
"image_id": "a6893756-b108-4667-9bf3-7a02d076b3e2",
#.........这里部分代码省略.........
示例3: TestRackspaceCtrl
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrl(unittest.TestCase):
def setUp(self):
""" Set up the objects used by most of the tests. """
self.ctrl = RackspaceCtrl('valid_user', 'valid_api_key', 'http://foo.bar:8888')
self.ctrl.post_fn = stub_rackspace_identity_post
self.driver_cls = MockLibCloudDriver
def test_authenticate_valid_user(self):
""" Test authentication with a valid user and api key. """
auth_result = self.ctrl.authenticate()
self.assertEqual(auth_result, True)
self.assertIsNotNone(self.ctrl.token)
def test_authenticate_empty_user(self):
""" Ensure authentication with empty string as username fails. """
ctrl = RackspaceCtrl('', 'valid_api_key', 'http://foo.bar:8888')
ctrl.post_fn = stub_rackspace_identity_post
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_empty_apikey(self):
""" Ensure authentication with empty string as api_key fails. """
ctrl = RackspaceCtrl('valid_user', '', 'http://foo.bar:8888')
ctrl.post_fn = stub_rackspace_identity_post
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_invalid_user(self):
""" Ensure authentication with invalid user credentials fails. """
ctrl = RackspaceCtrl('invalid_user', 'invalid_api_key', 'http://foo.bar:8888')
ctrl.post_fn = stub_rackspace_identity_post
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_list_regions(self):
""" Ensure that list_regions returns the correct result. """
self.ctrl.authenticate()
regions = self.ctrl.list_regions()
expected_regions = [
{'IAD': 'iad'},
{'DFW': 'dfw'},
{'SYD': 'syd'},
{'ORD': 'ord'}
]
self.assertCountEqual(regions, expected_regions)
def test_set_region(self):
""" Ensure that set_region sets 'region' and 'driver'. """
self.ctrl.authenticate()
result = self.ctrl.set_region('iad')
self.assertEqual(result, True)
self.assertEqual(self.ctrl.region, 'iad')
self.assertIsNotNone(self.ctrl.driver)
def test_set_invalid_region(self):
""" Ensure that calling 'set_region' with an invalid param fails. """
self.ctrl.authenticate()
result = self.ctrl.set_region('invalid')
self.assertEqual(result, False)
self.assertIsNone(self.ctrl.region)
self.assertIsNone(self.ctrl.driver)
def test_token_parsed(self):
""" Ensure that the token is set. """
ctrl = RackspaceCtrl('valid_user', 'valid_api_key', 'http://foo.bar:8888')
ctrl.post_fn = stub_rackspace_identity_post
ctrl.authenticate()
self.assertEqual('abcdefgh0123456789', ctrl.token)
示例4: TestRackspaceCtrl
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrl(unittest.TestCase):
def setUp(self):
# prefix to identify created objects
self.object_prefix = "int_test_"
self.prefix_length = len(self.object_prefix)
self.ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
self.ctrl.authenticate()
self.ctrl.set_region('ord')
self.gns3_image = None
def tearDown(self):
self._remove_instances()
self._remove_key_pairs()
if self.gns3_image is not None:
self.ctrl.driver.ex_delete_image(self.gns3_image)
def _remove_instances(self):
""" Remove any instances that were created. """
for instance in self.ctrl.driver.list_nodes():
if instance.name[0:self.prefix_length] == self.object_prefix:
self.ctrl.driver.destroy_node(instance)
def _remove_key_pairs(self):
""" Remove any key pairs that were created. """
for key_pair in self.ctrl.driver.list_key_pairs():
if key_pair.name[0:self.prefix_length] == self.object_prefix:
self.ctrl.driver.delete_key_pair(key_pair)
def test_authenticate_valid_user(self):
""" Test authentication with a valid user and api key. """
ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, True)
self.assertIsNotNone(ctrl.token)
def test_authenticate_empty_user(self):
""" Ensure authentication with empty string as username fails. """
ctrl = RackspaceCtrl('', self.api_key, 'http://foo.bar:8888')
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_empty_apikey(self):
""" Ensure authentication with empty string as api_key fails. """
ctrl = RackspaceCtrl(self.username, '', 'http://foo.bar:8888')
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_invalid_user(self):
""" Ensure authentication with invalid user credentials fails. """
ctrl = RackspaceCtrl('invalid_user', 'invalid_api_key', 'http://foo.bar:8888')
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_set_region(self):
""" Ensure that set_region sets 'region' and 'driver'. """
ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
ctrl.authenticate()
result = ctrl.set_region('iad')
self.assertEqual(result, True)
self.assertEqual(ctrl.region, 'iad')
self.assertIsNotNone(ctrl.driver)
def test_set_invalid_region(self):
""" Ensure that calling 'set_region' with an invalid param fails. """
ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
ctrl.authenticate()
result = self.ctrl.set_region('invalid')
self.assertEqual(result, False)
self.assertIsNone(ctrl.region)
self.assertIsNone(ctrl.driver)
def test_create_instance(self):
""" Test creating an instance. """
name = "%screate_instance" % self.object_prefix
image = self.ctrl.driver.list_images()[0]
size = self.ctrl.driver.list_sizes()[0]
key_pair = self.ctrl.create_key_pair(name)
instance = self.ctrl.create_instance(name, size, image, key_pair)
#.........这里部分代码省略.........
示例5: TestRackspaceCtrlDriver
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrlDriver(unittest.TestCase):
""" Test the libcloud Rackspace driver. """
class StubObject(object):
def __init__(self, **kwargs):
for arg in kwargs:
setattr(self, arg, kwargs[arg])
def setUp(self):
""" Set up the objects used by most of the tests. """
self.ctrl = RackspaceCtrl('valid_user', 'valid_api_key')
self.ctrl.post_fn = stub_rackspace_identity_post
self.ctrl.driver_cls = MockLibCloudDriver
self.ctrl.authenticate()
self.ctrl.set_region('iad')
self.key_pair = TestRackspaceCtrlDriver.StubObject(public_key='keystr')
def test_create_instance_over_limit(self):
""" Ensure '413 Over Limit' error is handled properly. """
self.assertRaises(OverLimit, self.ctrl.create_instance,
'over_limit', 'size', 'image', self.key_pair)
def test_create_instance_bad_request(self):
""" Ensure '400 Bad Request' error is handled properly. """
self.assertRaises(BadRequest, self.ctrl.create_instance,
'bad_request', 'size', 'image', self.key_pair)
def test_delete_instance_nonexistant(self):
""" Ensure '404 Instance not found' error is handled properly. """
instance = TestRackspaceCtrlDriver.StubObject(name='nonexistant')
self.assertRaises(ItemNotFound, self.ctrl.delete_instance,
instance)
def test_create_key_pair_duplicate_name(self):
""" Ensure '409 Key Pair exists' error is handled properly. """
self.assertRaises(KeyPairExists, self.ctrl.create_key_pair,
'duplicate_name')
def test_service_uavailable(self):
""" Ensure '503 Service Unavailable' error is handled properly. """
self.assertRaises(ServiceUnavailable, self.ctrl.create_instance,
'service_unavailable', 'size', 'image',
self.key_pair)
def test_unauthorized(self):
""" Ensure '401 Unauthroized' error is handled properly. """
self.assertRaises(Unauthorized, self.ctrl.create_instance,
'unauthorized', 'size', 'image', self.key_pair)
def test_api_error(self):
""" Ensure '500 ...' error is handled properly. """
self.assertRaises(ApiError, self.ctrl.create_instance, 'api_error',
'size', 'image', self.key_pair)
示例6: TestRackspaceCtrl
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrl(unittest.TestCase):
def setUp(self):
self.username = username
self.api_key = api_key
# prefix to identify created objects
self.object_prefix = "int_test_"
self.prefix_length = len(self.object_prefix)
self.ctrl = RackspaceCtrl(self.username, self.api_key)
self.ctrl.authenticate()
self.ctrl.set_region('ord')
def tearDown(self):
self._remove_instances()
self._remove_key_pairs()
def _remove_instances(self):
""" Remove any instances that were created. """
for instance in self.ctrl.driver.list_nodes():
if instance.name[0:self.prefix_length] == self.object_prefix:
self.ctrl.driver.destroy_node(instance)
def _remove_key_pairs(self):
""" Remove any key pairs that were created. """
for key_pair in self.ctrl.driver.list_key_pairs():
if key_pair.name[0:self.prefix_length] == self.object_prefix:
self.ctrl.driver.delete_key_pair(key_pair)
def test_authenticate_valid_user(self):
""" Test authentication with a valid user and api key. """
ctrl = RackspaceCtrl(self.username, self.api_key)
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, True)
self.assertIsNotNone(ctrl.token)
def test_authenticate_empty_user(self):
""" Ensure authentication with empty string as username fails. """
ctrl = RackspaceCtrl('', self.api_key)
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_empty_apikey(self):
""" Ensure authentication with empty string as api_key fails. """
ctrl = RackspaceCtrl(self.username, '')
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_invalid_user(self):
""" Ensure authentication with invalid user credentials fails. """
ctrl = RackspaceCtrl('invalid_user', 'invalid_api_key')
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_set_region(self):
""" Ensure that set_region sets 'region' and 'driver'. """
ctrl = RackspaceCtrl(self.username, self.api_key)
ctrl.authenticate()
result = ctrl.set_region('iad')
self.assertEqual(result, True)
self.assertEqual(ctrl.region, 'iad')
self.assertIsNotNone(ctrl.driver)
def test_set_invalid_region(self):
""" Ensure that calling 'set_region' with an invalid param fails. """
ctrl = RackspaceCtrl(self.username, self.api_key)
ctrl.authenticate()
result = self.ctrl.set_region('invalid')
self.assertEqual(result, False)
self.assertIsNone(ctrl.region)
self.assertIsNone(ctrl.driver)
def test_create_instance(self):
""" Test creating an instance. """
name = "%screate_instance" % self.object_prefix
image = self.ctrl.driver.list_images()[0]
size = self.ctrl.driver.list_sizes()[0]
key_pair = self.ctrl.create_key_pair(name)
instance = self.ctrl.create_instance(name, size, image, key_pair)
#.........这里部分代码省略.........
示例7: TestRackspaceCtrl
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrl(unittest.TestCase):
def setUp(self):
# prefix to identify created objects
self.object_prefix = "int_test_"
self.prefix_length = len(self.object_prefix)
self.ctrl = RackspaceCtrl(self.username, self.api_key, "http://foo.bar:8888")
self.ctrl.authenticate()
self.ctrl.set_region("ord")
self.gns3_image = None
self.ctrl.GNS3_CONTAINER_NAME = "TEST_GNS3"
def tearDown(self):
self._remove_instances()
self._remove_key_pairs()
if self.gns3_image is not None:
self.ctrl.driver.ex_delete_image(self.gns3_image)
def _remove_instances(self):
""" Remove any instances that were created. """
for instance in self.ctrl.driver.list_nodes():
if instance.name[0 : self.prefix_length] == self.object_prefix:
self.ctrl.driver.destroy_node(instance)
def _delete_container(self):
try:
container = self.ctrl.storage_driver.get_container(self.ctrl.GNS3_CONTAINER_NAME)
for o in container.iterate_objects():
o.delete()
container.delete()
except ContainerDoesNotExistError:
pass
def _remove_key_pairs(self):
""" Remove any key pairs that were created. """
for key_pair in self.ctrl.driver.list_key_pairs():
if key_pair.name[0 : self.prefix_length] == self.object_prefix:
self.ctrl.driver.delete_key_pair(key_pair)
def test_authenticate_valid_user(self):
""" Test authentication with a valid user and api key. """
ctrl = RackspaceCtrl(self.username, self.api_key, "http://foo.bar:8888")
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, True)
self.assertIsNotNone(ctrl.token)
def test_authenticate_empty_user(self):
""" Ensure authentication with empty string as username fails. """
ctrl = RackspaceCtrl("", self.api_key, "http://foo.bar:8888")
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_empty_apikey(self):
""" Ensure authentication with empty string as api_key fails. """
ctrl = RackspaceCtrl(self.username, "", "http://foo.bar:8888")
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_invalid_user(self):
""" Ensure authentication with invalid user credentials fails. """
ctrl = RackspaceCtrl("invalid_user", "invalid_api_key", "http://foo.bar:8888")
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_set_region(self):
""" Ensure that set_region sets 'region' and 'driver'. """
ctrl = RackspaceCtrl(self.username, self.api_key, "http://foo.bar:8888")
ctrl.authenticate()
result = ctrl.set_region("iad")
self.assertEqual(result, True)
self.assertEqual(ctrl.region, "iad")
self.assertIsNotNone(ctrl.driver)
def test_set_invalid_region(self):
""" Ensure that calling 'set_region' with an invalid param fails. """
ctrl = RackspaceCtrl(self.username, self.api_key, "http://foo.bar:8888")
ctrl.authenticate()
result = self.ctrl.set_region("invalid")
self.assertEqual(result, False)
self.assertIsNone(ctrl.region)
#.........这里部分代码省略.........
示例8: TestRackspaceCtrl
# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import set_region [as 别名]
class TestRackspaceCtrl(unittest.TestCase):
def setUp(self):
""" Set up the objects used by most of the tests. """
self.ctrl = RackspaceCtrl("valid_user", "valid_api_key", "http://foo.bar:8888")
self.ctrl.post_fn = stub_rackspace_identity_post
self.driver_cls = MockLibCloudDriver
def test_authenticate_valid_user(self):
""" Test authentication with a valid user and api key. """
auth_result = self.ctrl.authenticate()
self.assertEqual(auth_result, True)
self.assertIsNotNone(self.ctrl.token)
def test_authenticate_empty_user(self):
""" Ensure authentication with empty string as username fails. """
ctrl = RackspaceCtrl("", "valid_api_key", "http://foo.bar:8888")
ctrl.post_fn = stub_rackspace_identity_post
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_empty_apikey(self):
""" Ensure authentication with empty string as api_key fails. """
ctrl = RackspaceCtrl("valid_user", "", "http://foo.bar:8888")
ctrl.post_fn = stub_rackspace_identity_post
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_authenticate_invalid_user(self):
""" Ensure authentication with invalid user credentials fails. """
ctrl = RackspaceCtrl("invalid_user", "invalid_api_key", "http://foo.bar:8888")
ctrl.post_fn = stub_rackspace_identity_post
auth_result = ctrl.authenticate()
self.assertEqual(auth_result, False)
self.assertIsNone(ctrl.token)
def test_list_regions(self):
""" Ensure that list_regions returns the correct result. """
self.ctrl.authenticate()
regions = self.ctrl.list_regions()
expected_regions = [{"IAD": "iad"}, {"DFW": "dfw"}, {"SYD": "syd"}, {"ORD": "ord"}]
self.assertCountEqual(regions, expected_regions)
def test_set_region(self):
""" Ensure that set_region sets 'region' and 'driver'. """
self.ctrl.authenticate()
result = self.ctrl.set_region("iad")
self.assertEqual(result, True)
self.assertEqual(self.ctrl.region, "iad")
self.assertIsNotNone(self.ctrl.driver)
def test_set_invalid_region(self):
""" Ensure that calling 'set_region' with an invalid param fails. """
self.ctrl.authenticate()
result = self.ctrl.set_region("invalid")
self.assertEqual(result, False)
self.assertIsNone(self.ctrl.region)
self.assertIsNone(self.ctrl.driver)
def test_token_parsed(self):
""" Ensure that the token is set. """
ctrl = RackspaceCtrl("valid_user", "valid_api_key", "http://foo.bar:8888")
ctrl.post_fn = stub_rackspace_identity_post
ctrl.authenticate()
self.assertEqual("abcdefgh0123456789", ctrl.token)
def test_upload_file(self):
self.ctrl.storage_driver = mock.MagicMock()
mock_container = mock.MagicMock()
mock_container.list_objects = mock.MagicMock(return_value=[])
self.ctrl.storage_driver.create_container = mock.MagicMock(return_value=mock_container)
test_data = b"abcdef"
test_data_hash = hashlib.md5(test_data).hexdigest()
test_file = tempfile.NamedTemporaryFile()
with test_file.file as f:
f.write(test_data)
return_value = self.ctrl.upload_file(test_file.name, "test_folder/test.txt")
#.........这里部分代码省略.........