當前位置: 首頁>>代碼示例>>Python>>正文


Python ProfitBricksService.update_server方法代碼示例

本文整理匯總了Python中profitbricks.client.ProfitBricksService.update_server方法的典型用法代碼示例。如果您正苦於以下問題:Python ProfitBricksService.update_server方法的具體用法?Python ProfitBricksService.update_server怎麽用?Python ProfitBricksService.update_server使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在profitbricks.client.ProfitBricksService的用法示例。


在下文中一共展示了ProfitBricksService.update_server方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestServer

# 需要導入模塊: from profitbricks.client import ProfitBricksService [as 別名]
# 或者: from profitbricks.client.ProfitBricksService import update_server [as 別名]
class TestServer(unittest.TestCase):
    def setUp(self):
        self.server = ProfitBricksService(
            username='username', password='password')

    def test_list_servers(self):
        servers = self.server.list_servers(datacenter_id=datacenter_id)

        self.assertEqual(len(servers), 4)
        self.assertEqual(servers['items'][0]['id'], server_id)
        self.assertEqual(servers['items'][0]['properties']['name'], 'New Server')
        self.assertEqual(servers['items'][0]['properties']['cores'], '4')
        self.assertEqual(servers['items'][0]['properties']['ram'], '4096')
        self.assertEqual(servers['items'][0]['properties']['availabilityZone'], 'ZONE_1')
        self.assertEqual(servers['items'][0]['properties']['vmState'], 'SHUTOFF')
        self.assertEqual(servers['items'][0]['properties']['bootVolume'], None)
        self.assertEqual(servers['items'][0]['properties']['bootCdrom'], None)

    def test_get_server(self):
        server = self.server.get_server(
            datacenter_id=datacenter_id,
            server_id=server_id)

        self.assertEqual(server['id'], server_id)
        self.assertEqual(server['properties']['name'], 'New Server')
        self.assertEqual(server['properties']['cores'], '4')
        self.assertEqual(server['properties']['ram'], '4096')
        self.assertEqual(server['properties']['availabilityZone'], 'ZONE_1')
        self.assertEqual(server['properties']['vmState'], 'SHUTOFF')
        self.assertEqual(server['properties']['bootVolume'], None)
        self.assertEqual(server['properties']['bootCdrom'], None)

    def test_delete_server(self):
        server = self.server.delete_server(
            datacenter_id=datacenter_id,
            server_id=server_id)

        self.assertTrue(server)

    def test_update_server(self):
        server = self.server.update_server(
            datacenter_id=datacenter_id,
            server_id=server_id,
            cores=16)

        self.assertEqual(server['id'], server_id)
        self.assertEqual(server['properties']['name'], 'server1 - updated')
        self.assertEqual(server['properties']['cores'], '16')
        self.assertEqual(server['properties']['ram'], '4096')
        self.assertEqual(server['properties']['availabilityZone'], 'ZONE_1')
        self.assertEqual(server['properties']['bootVolume']['id'], '<ID-OF-ANOTHER-STORAGE>')
        self.assertEqual(server['properties']['bootCdrom'], None)

    def test_create_complex(self):
        nic1 = NIC(
            name='nic1',
            ips=['10.2.2.3'],
            dhcp='true',
            lan=1,
            firewall_active=True,
            )

        nic2 = NIC(
            name='nic2',
            ips=['10.2.3.4'],
            dhcp='true',
            lan=1,
            firewall_active=True,
            )

        volume1 = Volume(
            name='volume1',
            size=56,
            image='<IMAGE/SNAPSHOT-ID>',
            bus='VIRTIO'
            )

        volume2 = Volume(
            name='volume2',
            size=56,
            image='<IMAGE/SNAPSHOT-ID>',
            bus='VIRTIO'
            )

        nics = [nic1, nic2]
        create_volumes = [volume1, volume2]

        i = Server(
            name='server1',
            ram=4096,
            cores=4,
            nics=nics,
            create_volumes=create_volumes
            )

        response = self.server.create_server(
            datacenter_id=datacenter_id, server=i)

        self.assertEqual(response['id'], server_id)
        self.assertEqual(response['properties']['name'], 'New Server')
#.........這裏部分代碼省略.........
開發者ID:grandvizier,項目名稱:profitbricks-sdk-python,代碼行數:103,代碼來源:test_server.py

示例2: TestServer

# 需要導入模塊: from profitbricks.client import ProfitBricksService [as 別名]
# 或者: from profitbricks.client.ProfitBricksService import update_server [as 別名]
class TestServer(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter.
        self.datacenter = self.client.create_datacenter(
            datacenter=Datacenter(**self.resource['datacenter']))
        wait_for_completion(self.client, self.datacenter, 'create_datacenter')

        # Create test volume1.
        self.volume1 = self.client.create_volume(
            datacenter_id=self.datacenter['id'],
            volume=Volume(**self.resource['volume']))
        wait_for_completion(self.client, self.volume1, 'create_volume')

        # Create test volume2 (attach volume test).
        self.volume2 = self.client.create_volume(
            datacenter_id=self.datacenter['id'],
            volume=Volume(**self.resource['volume']))
        wait_for_completion(self.client, self.volume2, 'create_volume')

        # Create test server.
        server = Server(**self.resource['server'])
        server.attach_volumes = [self.volume1['id']]
        self.server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=server)
        wait_for_completion(self.client, self.server, 'create_server')

        # Create test NIC.
        self.nic = self.client.create_nic(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id'],
            nic=NIC(**self.resource['nic']))
        wait_for_completion(self.client, self.nic, 'create_nic')

        # Find an Ubuntu image for testing.
        for item in self.client.list_images()['items']:
            if 'Ubuntu-15' in item['properties']['name'] and item['properties']['location'] == configuration.LOCATION:
                self.image = item

    @classmethod
    def tearDownClass(self):
        self.client.delete_datacenter(datacenter_id=self.datacenter['id'])

    def test_list(self):
        servers = self.client.list_servers(datacenter_id=self.datacenter['id'])

        self.assertGreater(len(servers), 0)
        self.assertEqual(servers['items'][0]['type'], 'server')
        assertRegex(self, servers['items'][0]['id'], self.resource['uuid_match'])

    def test_get(self):
        server = self.client.get_server(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id']
        )

        self.assertEqual(server['type'], 'server')
        self.assertEqual(server['id'], self.server['id'])
        self.assertEqual(server['properties']['name'], self.resource['server']['name'])
        self.assertEqual(server['properties']['cores'], self.resource['server']['cores'])
        self.assertEqual(server['properties']['ram'], self.resource['server']['ram'])

    def test_delete(self):
        server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=Server(**self.resource['server'])
        )
        wait_for_completion(self.client, server, 'create_server')

        response = self.client.delete_server(
            datacenter_id=self.datacenter['id'],
            server_id=server['id']
        )

        self.assertTrue(response)

    def test_update(self):
        server = self.client.update_server(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id'],
            name=self.resource['server']['name'] + ' RENAME')
        wait_for_completion(self.client, server, 'update_server')
        server = self.client.get_server(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id']
        )

        self.assertEqual(server['id'], self.server['id'])
        self.assertEqual(server['properties']['name'], self.resource['server']['name'] + ' RENAME')
        self.assertEqual(server['properties']['cores'], self.resource['server']['cores'])
        self.assertEqual(server['properties']['ram'], self.resource['server']['ram'])

    def test_create_simple(self):
#.........這裏部分代碼省略.........
開發者ID:jbuchhammer,項目名稱:profitbricks-sdk-python,代碼行數:103,代碼來源:test_server_live.py

示例3: ProfitBricksService

# 需要導入模塊: from profitbricks.client import ProfitBricksService [as 別名]
# 或者: from profitbricks.client.ProfitBricksService import update_server [as 別名]
"""Delete Server
"""
from profitbricks.client import ProfitBricksService

datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'

client = ProfitBricksService(
    username='username', password='password')

server = client.delete_server(
    datacenter_id=datacenter_id,
    server_id=server_id)

"""Update Server
"""
from profitbricks.client import ProfitBricksService

datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'

client = ProfitBricksService(
    username='username', password='password')

server = client.update_server(
    datacenter_id=datacenter_id,
    server_id=server_id,
    cores=35,
    ram=2048)
開發者ID:grandvizier,項目名稱:profitbricks-sdk-python,代碼行數:31,代碼來源:server_example.py


注:本文中的profitbricks.client.ProfitBricksService.update_server方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。