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


Python client.ProfitBricksService類代碼示例

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


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

示例1: TestImage

class TestImage(unittest.TestCase):
    def setUp(self):
        self.image = ProfitBricksService(
            username='username', password='password')

    def test_list_images(self):
        images = self.image.list_images()

        self.assertEqual(len(images), 4)
        self.assertEqual(
            images['items'][0]['id'], '7df81087-5835-41c6-a10b-3e098593bbd2')

    def test_get_image(self):
        image_id = '7df81087-5835-41c6-a10b-3e098593bbd2'
        image = self.image.get_image(image_id)

        self.assertEqual(image['properties']['name'], 'Ubuntu 14.04')

    def test_delete_image(self):
        image_id = '7df81087-5835-41c6-a10b-3e098593bbd2'

        image = self.image.delete_image(image_id)
        self.assertTrue(image)

    def test_update_image(self):
        image_id = '7df81087-5835-41c6-a10b-3e098593bbd2'
        image = self.image.update_image(
            image_id,
            name='New name')

        self.assertEqual(image['properties']['name'], 'New name')
開發者ID:grandvizier,項目名稱:profitbricks-sdk-python,代碼行數:31,代碼來源:test_image.py

示例2: TestImage

class TestImage(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # 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

    def test_list_images(self):
        images = self.client.list_images()

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

    def test_get_image(self):
        image = self.client.get_image(self.image['id'])

        self.assertEqual(image['type'], 'image')
        self.assertEqual(image['id'], self.image['id'])
        self.assertIn(image['properties']['imageType'], ['HDD', 'CDROM'])
開發者ID:jbuchhammer,項目名稱:profitbricks-sdk-python,代碼行數:27,代碼來源:test_image_live.py

示例3: TestIPBlock

class TestIPBlock(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        ipblock1 = IPBlock(**self.resource['ipblock'])
        self.ipblock1 = self.client.reserve_ipblock(ipblock1)

        ipblock2 = IPBlock(**self.resource['ipblock'])
        self.ipblock2 = self.client.reserve_ipblock(ipblock2)

    @classmethod
    def tearDownClass(self):
        self.client.delete_ipblock(self.ipblock1['id'])

    def test_list_ipblocks(self):
        ipblocks = self.client.list_ipblocks()

        assertRegex(self, ipblocks['items'][0]['id'], self.resource['uuid_match'])
        self.assertGreater(len(ipblocks), 0)
        assertRegex(self, ipblocks['items'][0]['id'], self.resource['uuid_match'])
        self.assertGreater(ipblocks['items'][0]['properties']['size'], 0)
        self.assertIn(ipblocks['items'][0]['properties']['location'], self.resource['locations'])

    def test_get_ipblock(self):
        ipblock = self.client.get_ipblock(self.ipblock1['id'])

        assertRegex(self, ipblock['id'], self.resource['uuid_match'])
        self.assertEqual(ipblock['id'], self.ipblock1['id'])
        self.assertEqual(ipblock['properties']['name'], (self.resource['ipblock']['name']))
        self.assertEqual(ipblock['properties']['size'], self.resource['ipblock']['size'])
        self.assertEqual(ipblock['properties']['location'], self.resource['ipblock']['location'])

    def test_delete_ipblock(self):
        ipblock = self.client.delete_ipblock(self.ipblock2['id'])

        self.assertTrue(ipblock)

    def test_reserve_ipblock(self):
        ipblock = self.client.reserve_ipblock(IPBlock(**self.resource['ipblock']))

        assertRegex(self, ipblock['id'], self.resource['uuid_match'])
        self.assertEqual(ipblock['properties']['name'], (self.resource['ipblock']['name']))
        self.assertEqual(ipblock['properties']['size'], self.resource['ipblock']['size'])
        self.assertEqual(ipblock['properties']['location'], self.resource['ipblock']['location'])

        self.client.delete_ipblock(ipblock['id'])
開發者ID:fbrehm,項目名稱:profitbricks-sdk-python,代碼行數:51,代碼來源:test_ipblock_live.py

示例4: setUpClass

    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 volume
        self.volume = self.client.create_volume(
            datacenter_id=self.datacenter['id'],
            volume=Volume(**self.resource['volume']))
        wait_for_completion(self.client, self.volume, 'create_volume')

        # Create snapshot1
        self.snapshot1 = self.client.create_snapshot(
            datacenter_id=self.datacenter['id'],
            volume_id=self.volume['id'],
            name=self.resource['snapshot']['name'],
            description=self.resource['snapshot']['description'])
        wait_for_completion(self.client, self.snapshot1, 'create_snapshot1',
                            wait_timeout=600)

        self.image = find_image(self.client, configuration.IMAGE_NAME)
開發者ID:fbrehm,項目名稱:profitbricks-sdk-python,代碼行數:28,代碼來源:test_volume_live.py

示例5: setUpClass

    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']))
開發者ID:fbrehm,項目名稱:profitbricks-sdk-python,代碼行數:10,代碼來源:test_datacenter_live.py

示例6: TestLocation

class TestLocation(unittest.TestCase):
    def setUp(self):
        self.location = ProfitBricksService(
            username='username', password='password')

    def test_list_locations(self):
        locations = self.location.list_locations()

        self.assertEqual(len(locations), 4)
        self.assertEqual(locations['items'][0]['id'], 'de/fra')
        self.assertEqual(
            locations['items'][0]['properties']['name'], 'Europe / Germany / Frankfurt')

    def test_get_location(self):
        location = self.location.get_location(location_id)

        self.assertEqual(location['id'], 'de/fra')
        self.assertEqual(
            location['properties']['name'], 'Europe / Germany / Frankfurt')
開發者ID:grandvizier,項目名稱:profitbricks-sdk-python,代碼行數:19,代碼來源:test_location.py

示例7: setUpClass

    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # 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
開發者ID:jbuchhammer,項目名稱:profitbricks-sdk-python,代碼行數:11,代碼來源:test_image_live.py

示例8: setUpClass

    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        ipblock1 = IPBlock(**self.resource['ipblock'])
        self.ipblock1 = self.client.reserve_ipblock(ipblock1)

        ipblock2 = IPBlock(**self.resource['ipblock'])
        self.ipblock2 = self.client.reserve_ipblock(ipblock2)
開發者ID:fbrehm,項目名稱:profitbricks-sdk-python,代碼行數:12,代碼來源:test_ipblock_live.py

示例9: TestProvisioningRequest

class TestProvisioningRequest(unittest.TestCase):
    def setUp(self):
        self.provisioning_request = ProfitBricksService(username="username", password="password")

    def test_list_requests(self):
        prov_requests = self.provisioning_request.list_requests()

        self.assertEqual(len(prov_requests), 4)
        self.assertEqual(prov_requests["items"][0]["id"], "59359eae-cdcd-406f-900b-58b3ad9d8de9")

    def test_get_request(self):
        request_id = "59359eae-cdcd-406f-900b-58b3ad9d8de9"
        prov_request = self.provisioning_request.get_request(request_id)

        self.assertEqual(prov_request["metadata"]["createdBy"], "User X")

    def test_get_request_with_status(self):
        request_id = "59359eae-cdcd-406f-900b-58b3ad9d8de9"
        prov_request = self.provisioning_request.get_request(request_id, status=True)

        self.assertEqual(prov_request["metadata"]["requestStatus"], "RUNNING")
開發者ID:grandvizier,項目名稱:profitbricks-sdk-python,代碼行數:21,代碼來源:test_provisioning_requests.py

示例10: TestLocation

class TestLocation(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME, password=configuration.PASSWORD, headers=configuration.HEADERS
        )

    def test_list_locations(self):
        locations = self.client.list_locations()

        self.assertEqual(len(locations), 4)
        for location in locations["items"]:
            self.assertEqual(location["type"], "location")
            self.assertIn(location["id"], self.resource["locations"])

    def test_get_location(self):
        location = self.client.get_location(configuration.LOCATION)

        self.assertEqual(location["type"], "location")
        self.assertEqual(location["id"], configuration.LOCATION)
開發者ID:fbrehm,項目名稱:profitbricks-sdk-python,代碼行數:21,代碼來源:test_location_live.py

示例11: TestIPBlock

class TestIPBlock(unittest.TestCase):
    def setUp(self):
        self.ipblock = ProfitBricksService(
            username='username', password='password')

    def test_list_ipblocks(self):
        ipblocks = self.ipblock.list_ipblocks()

        self.assertEqual(len(ipblocks), 4)
        self.assertEqual(ipblocks['items'][0]['id'], ipblock_id)
        self.assertEqual(
            ipblocks['items'][0]['properties']['size'], 5)
        self.assertEqual(
            ipblocks['items'][0]['properties']['location'], 'de/fra')

    def test_get_ipblock(self):
        ipblock = self.ipblock.get_ipblock(ipblock_id)

        self.assertEqual(ipblock['id'], ipblock_id)
        self.assertEqual(ipblock['properties']['size'], 5)
        self.assertEqual(
            ipblock['properties']['location'], 'de/fra')

    def test_delete_ipblock(self):
        ipblock = self.ipblock.delete_ipblock(ipblock_id)
        self.assertTrue(ipblock)

    def test_reserve_ipblock(self):
        i = IPBlock(location='de/fra', size=5)

        ipblock = self.ipblock.reserve_ipblock(i)

        self.assertEqual(ipblock['id'], ipblock_id)
        self.assertEqual(ipblock['properties']['size'], 5)
        self.assertEqual(
            ipblock['properties']['location'], 'de/fra')
開發者ID:grandvizier,項目名稱:profitbricks-sdk-python,代碼行數:36,代碼來源:test_ipblock.py

示例12: TestLan

class TestLan(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 LAN.
        self.lan = self.client.create_lan(
            datacenter_id=self.datacenter['id'],
            lan=LAN(**self.resource['lan']))
        wait_for_completion(self.client, self.lan, 'create_lan')

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

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

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

    @classmethod
    def tearDownClass(self):
        self.client.delete_datacenter(datacenter_id=self.datacenter['id'])
開發者ID:fbrehm,項目名稱:profitbricks-sdk-python,代碼行數:47,代碼來源:test_lan_live.py

示例13: setUpClass

    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
開發者ID:jbuchhammer,項目名稱:profitbricks-sdk-python,代碼行數:43,代碼來源:test_server_live.py

示例14: TestServer

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,代碼行數:101,代碼來源:test_server.py

示例15: ConfigParser

from datetime import datetime, timedelta
from profitbricks.client import ProfitBricksService
from time import sleep

# read config
config = ConfigParser()
config.read('settings.cfg')

datacenter_id = config.get('snapshots', 'datacenter_id')
snapshot_prefix = config.get('snapshots', 'snapshot_prefix')
retention_time = config.getint('snapshots', 'retention_time')
sleep_seconds = config.getint('snapshots', 'sleep_seconds')

pb = ProfitBricksService(
    username=config.get('credentials', 'username'),
    password=config.get('credentials', 'password'),
)

# timestamp for creating and deleting
now = datetime.now()

# create new snapshots from list of volumes in datacenter
volumes = pb.list_volumes(datacenter_id=datacenter_id)

for volume_item in volumes['items']:
    volume_id = volume_item['id']
    volume = pb.get_volume(datacenter_id, volume_id)

    volume_name = volume['properties']['name']
    snapshot_name = "{}-{}-{}".format(snapshot_prefix, now.strftime("%Y%m%d"), volume_name)
開發者ID:seibert-media,項目名稱:profitbricks-snapshot,代碼行數:30,代碼來源:profitbricks-snapshot.py


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