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


Python ProfitBricksService.create_datacenter方法代码示例

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


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

示例1: TestLan

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
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,代码行数:49,代码来源:test_lan_live.py

示例2: TestServer

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [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: TestDatacenter

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
class TestDatacenter(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']))

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

    def test_list(self):
        datacenters = self.client.list_datacenters()

        self.assertGreater(len(datacenters), 0)
        self.assertEqual(datacenters['items'][0]['type'], 'datacenter')

    def test_get(self):
        datacenter = self.client.get_datacenter(
            datacenter_id=self.datacenter['id'])

        assertRegex(self, datacenter['id'], self.resource['uuid_match'])
        self.assertEqual(datacenter['type'], 'datacenter')
        self.assertEqual(datacenter['id'], self.datacenter['id'])
        self.assertEqual(datacenter['properties']['name'], self.resource['datacenter']['name'])
        self.assertEqual(datacenter['properties']['description'], self.resource['datacenter']['description'])
        self.assertEqual(datacenter['properties']['location'], self.resource['datacenter']['location'])

    def test_delete(self):
        datacenter = self.client.create_datacenter(
            datacenter=Datacenter(**self.resource['datacenter']))
        wait_for_completion(self.client, datacenter, 'create_datacenter')

        response = self.client.delete_datacenter(
            datacenter_id=datacenter['id'])

        self.assertTrue(response)

    def test_update(self):
        datacenter = self.client.update_datacenter(
            datacenter_id=self.datacenter['id'],
            description=self.resource['datacenter']['name']+' - RENAME')
        wait_for_completion(self.client, datacenter, 'update_datacenter')
        datacenter = self.client.get_datacenter(datacenter_id=self.datacenter['id'])

        assertRegex(self, datacenter['id'], self.resource['uuid_match'])
        self.assertEqual(datacenter['id'], self.datacenter['id'])
        self.assertEqual(datacenter['properties']['name'], self.resource['datacenter']['name'])
        self.assertEqual(datacenter['properties']['description'], self.resource['datacenter']['name']+' - RENAME')
        self.assertEqual(datacenter['properties']['location'], self.resource['datacenter']['location'])
        self.assertGreater(datacenter['properties']['version'], 1)

    def test_create_simple(self):
        datacenter = self.client.create_datacenter(
            datacenter=Datacenter(**self.resource['datacenter']))
        wait_for_completion(self.client, datacenter, 'create_datacenter')

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

        response = self.client.delete_datacenter(
            datacenter_id=datacenter['id'])
        self.assertTrue(response)
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:73,代码来源:test_datacenter_live.py

示例4: TestVolume

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
class TestVolume(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 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)

        # Create snapshot2 (used in delete test)
        self.snapshot2 = 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.snapshot2, 'create_snapshop2',
                            wait_timeout=600)

        self.image = find_image(self.client, configuration.IMAGE_NAME)

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

    def test_list_volumes(self):
        volumes = self.client.list_volumes(
            datacenter_id=self.datacenter['id'])

        self.assertGreater(len(volumes), 0)
        assertRegex(self, volumes['items'][0]['id'], self.resource['uuid_match'])
        self.assertEqual(volumes['items'][0]['type'], 'volume')
        self.assertEqual(volumes['items'][0]['properties']['name'], self.resource['volume']['name'])
        self.assertEqual(volumes['items'][0]['properties']['size'], self.resource['volume']['size'])
        self.assertEqual(volumes['items'][0]['properties']['licenceType'], self.resource['volume']['licence_type'])
        self.assertEqual(volumes['items'][0]['properties']['type'], self.resource['volume']['type'])
        self.assertFalse(volumes['items'][0]['properties']['cpuHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['cpuHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['ramHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['ramHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['nicHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['nicHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['discVirtioHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['discVirtioHotUnplug'])
        self.assertFalse(volumes['items'][0]['properties']['discScsiHotPlug'])
        self.assertFalse(volumes['items'][0]['properties']['discScsiHotUnplug'])
        self.assertIsNone(volumes['items'][0]['properties']['bus'])

    def test_get_volume(self):
        volume = self.client.get_volume(
            datacenter_id=self.datacenter['id'],
            volume_id=self.volume['id'])

        self.assertEqual(volume['id'], self.volume['id'])
        self.assertEqual(volume['type'], 'volume')
        self.assertEqual(volume['properties']['name'], self.resource['volume']['name'])
        self.assertEqual(volume['properties']['size'], self.resource['volume']['size'])
        self.assertEqual(volume['properties']['licenceType'], self.resource['volume']['licence_type'])
        self.assertEqual(volume['properties']['type'], self.resource['volume']['type'])
        self.assertFalse(volume['properties']['cpuHotPlug'])
        self.assertFalse(volume['properties']['cpuHotUnplug'])
        self.assertFalse(volume['properties']['ramHotPlug'])
        self.assertFalse(volume['properties']['ramHotUnplug'])
        self.assertFalse(volume['properties']['nicHotPlug'])
        self.assertFalse(volume['properties']['nicHotUnplug'])
        self.assertFalse(volume['properties']['discVirtioHotPlug'])
        self.assertFalse(volume['properties']['discVirtioHotUnplug'])
        self.assertFalse(volume['properties']['discScsiHotPlug'])
        self.assertFalse(volume['properties']['discScsiHotUnplug'])
        self.assertIsNone(volume['properties']['bus'])

    def test_delete_volume(self):
        volume = self.client.create_volume(
            datacenter_id=self.datacenter['id'],
            volume=Volume(**self.resource['volume']))
        wait_for_completion(self.client, volume, 'create_volume')

        volume = self.client.delete_volume(
            datacenter_id=self.datacenter['id'],
            volume_id=volume['id'])
#.........这里部分代码省略.........
开发者ID:jbuchhammer,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_volume_live.py

示例5: TestDatacenter

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
class TestDatacenter(unittest.TestCase):
    def setUp(self):
        self.datacenter = ProfitBricksService(username="username", password="password")

    def test_get_all(self):
        datacenters = self.datacenter.list_datacenters()

        self.assertEqual(len(datacenters), 4)
        self.assertEqual(datacenters["items"][0]["id"], datacenter_id)
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['name'], 'datacenter1')
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['description'], 'Description of my DC')
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['location'], 'de/fkb')
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['version'], 4)

    def test_get(self):
        datacenter = self.datacenter.get_datacenter(datacenter_id=datacenter_id)

        self.assertEqual(datacenter["id"], datacenter_id)
        self.assertEqual(datacenter["properties"]["name"], "datacenter1")
        self.assertEqual(datacenter["properties"]["description"], "Description of my DC")
        self.assertEqual(datacenter["properties"]["version"], 4)
        self.assertEqual(datacenter["properties"]["location"], "de/fkb")

    def test_delete(self):
        datacenter = self.datacenter.delete_datacenter(datacenter_id=datacenter_id)

        self.assertTrue(datacenter)

    def test_update(self):
        datacenter = self.datacenter.update_datacenter(
            datacenter_id=datacenter_id, name="Partially updated datacenter name"
        )

        self.assertEqual(datacenter["id"], datacenter_id)
        self.assertEqual(datacenter["properties"]["name"], "datacenter1")
        self.assertEqual(datacenter["properties"]["description"], "Description of my DC")
        self.assertEqual(datacenter["properties"]["version"], 4)
        self.assertEqual(datacenter["properties"]["location"], "de/fkb")

    def test_create_simple(self):
        i = Datacenter(name="datacenter1", description="My New Datacenter", location="de/fkb")

        response = self.datacenter.create_datacenter(datacenter=i)

        self.assertEqual(response["id"], datacenter_id)
        self.assertEqual(response["properties"]["name"], "datacenter1")
        self.assertEqual(response["properties"]["description"], "My New Datacenter")
        self.assertEqual(response["properties"]["version"], 4)
        self.assertEqual(response["properties"]["location"], "de/fkb")

    def test_create_complex(self):
        """
        Creates a complex Datacenter in a single request.

        """
        fwrule1 = FirewallRule(
            name="Open SSH port", protocol="TCP", source_mac="01:23:45:67:89:00", port_range_start=22
        )

        fwrule2 = FirewallRule(name="Allow PING", protocol="ICMP", icmp_type=8, icmp_code=0)

        fw_rules = [fwrule1, fwrule2]

        nic1 = NIC(name="nic1", ips=["10.2.2.3"], dhcp="true", lan=1, firewall_active=True, firewall_rules=fw_rules)

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

        nics = [nic1, nic2]

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

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

        volumes = [volume2]

        server1 = Server(name="server1", ram=4096, cores=4, nics=nics, create_volumes=[volume1])

        servers = [server1]

        balancednics = ["<NIC-ID-1>", "<NIC-ID-2>"]

        loadbalancer1 = LoadBalancer(name="My LB", balancednics=balancednics)

        loadbalancers = [loadbalancer1]

        lan1 = LAN(name="public Lan 4", public=True)

        lan2 = LAN(name="public Lan 4", public=True)

        lans = [lan1, lan2]

        d = Datacenter(
            name="datacenter1",
            description="my DC",
            location="de/fkb",
            servers=servers,
#.........这里部分代码省略.........
开发者ID:jbuchhammer,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_datacenter.py

示例6: main

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
def main(argv=None):
    '''Command line options.'''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = '%%(prog)s %s (%s)' % (program_version,
                                                     program_build_date)
    program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
    program_license = '''%s

  Created by Jürgen Buchhammer on %s.
  Copyright 2016 ProfitBricks GmbH. All rights reserved.

  Licensed under the Apache License 2.0
  http://www.apache.org/licenses/LICENSE-2.0

  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
''' % (program_shortdesc, str(__date__))

    try:
        # Setup argument parser
        parser = ArgumentParser(description=program_license,
                                formatter_class=RawDescriptionHelpFormatter)
        parser.add_argument('-u', '--user', dest='user', help='the login name')
        parser.add_argument('-p', '--password', dest='password',
                            help='the login password')
        parser.add_argument('-L', '--Login', dest='loginfile', default=None,
                            help='the login file to use')
        parser.add_argument('-t', '--type', dest='metatype',
                            default="OVF",
                            help='type of VM meta data')
        parser.add_argument('-m', '--metadata', dest='metafile',
                            required=True, default=None,
                            help='meta data file')
        parser.add_argument('-d', '--datacenterid', dest='datacenterid',
                            default=None,
                            help='datacenter of the new server')
        parser.add_argument('-D', '--DCname', dest='dcname', default=None,
                            help='new datacenter name')
        parser.add_argument('-l', '--location', dest='location', default=None,
                            help='location for new datacenter')
        parser.add_argument('-v', '--verbose', dest="verbose", action="count",
                            default=0,
                            help="set verbosity level [default: %(default)s]")
        parser.add_argument('-V', '--version', action='version',
                            version=program_version_message)

        # Process arguments
        args = parser.parse_args()
        global verbose
        verbose = args.verbose

        if verbose > 0:
            print("Verbose mode on")
            print("start {} with args {}".format(program_name, str(args)))

        (user, password) = getLogin(args.loginfile, args.user, args.password)
        if user is None or password is None:
            raise ValueError("user or password resolved to None")
        pbclient = ProfitBricksService(user, password)

        if args.metatype == 'OVF':
            metadata = OFVData(args.metafile)
            metadata.parse()
        else:
            sys.stderr.write("Metadata type '{}' is not supported"
                             .format(args.metatype))
            return 1

        # we need the DC first to have the location defined
        dc_id = None
        if args.datacenterid is None:
            if args.dcname is None or args.location is None:
                sys.stderr.write("Either '-d <id>' or '-D <name> -l <loc>'  must be specified")
                return 1
            # else: we will create the DC later after parsing the meta data
        else:
            dc_id = args.datacenterid

        if dc_id is None:
            location = args.location
            dc = Datacenter(name=args.dcname, location=location,
                            description="created by pb_importVM")
            print("create new DC {}".format(str(dc)))
            response = pbclient.create_datacenter(dc)
            dc_id = response['id']
            result = wait_for_request(pbclient, response['requestId'])
            print("wait loop returned {}".format(result))
        else:
            dc = pbclient.get_datacenter(dc_id)
            location = dc['properties']['location']
#.........这里部分代码省略.........
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:pb_importVM.py

示例7: TestLan

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
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'])

    def test_list_lans(self):
        lans = self.client.list_lans(datacenter_id=self.datacenter['id'])

        self.assertGreater(len(lans), 0)
        self.assertEqual(lans['items'][0]['type'], 'lan')
        self.assertIn(lans['items'][0]['id'], ('1', '2', '3'))
        self.assertEqual(lans['items'][0]['properties']['name'], self.resource['lan']['name'])
        self.assertTrue(lans['items'][0]['properties']['public'], self.resource['lan']['public'])

    def test_get_lan(self):
        lan = self.client.get_lan(datacenter_id=self.datacenter['id'], lan_id=self.lan['id'])

        self.assertEqual(lan['type'], 'lan')
        self.assertEqual(lan['id'], self.lan['id'])
        self.assertEqual(lan['properties']['name'], self.resource['lan']['name'])
        self.assertTrue(lan['properties']['public'], self.resource['lan']['public'])

    def test_delete_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')

        lan = self.client.delete_lan(datacenter_id=self.datacenter['id'], lan_id=lan['id'])

        self.assertTrue(lan)

    def test_update_lan(self):
        lan = self.client.update_lan(
            datacenter_id=self.datacenter['id'],
            lan_id=self.lan['id'],
            name=self.resource['lan']['name'] + ' RENAME',
            public=False)

        self.assertEqual(lan['type'], 'lan')
        self.assertEqual(lan['properties']['name'], self.resource['lan']['name'] + ' RENAME')
        self.assertFalse(lan['properties']['public'])

    def test_create_lan(self):
        self.assertEqual(self.lan['id'], '1')
        self.assertEqual(self.lan['type'], 'lan')
        self.assertEqual(self.lan['properties']['name'], self.resource['lan']['name'])
        self.assertEqual(self.lan['properties']['public'], self.resource['lan']['public'])

    def test_create_complex_lan(self):
        resource = NIC(**self.resource['nic'])

        nic1 = self.client.create_nic(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id'],
            nic=resource)
        wait_for_completion(self.client, nic1, 'create_nic1')
#.........这里部分代码省略.........
开发者ID:jbuchhammer,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_lan_live.py

示例8: ProfitBricksService

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
"""Create Simple Datacenter
"""
from profitbricks.client import ProfitBricksService
from profitbricks.client import Datacenter, Volume, Server

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

i = Datacenter(
    name='dc1',
    description='My New Datacenter',
    location='de/fkb'
    )

response = client.create_datacenter(datacenter=i)

"""Create Complex Datacenter
"""

from profitbricks.client import ProfitBricksService
from profitbricks.client import Datacenter, Volume, Server
from profitbricks.client import LAN, NIC, LoadBalancer, FirewallRule, IPBlock, Server


image_id = '226ed8c0-a2fe-11e4-b187-5f1f641608c8'

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

fwrule1 = FirewallRule(
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:32,代码来源:datacenter_example.py

示例9: main

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
def main(argv=None):
    """Parse command line options and create a server/volume composite."""

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = "%%(prog)s %s (%s)" % (program_version, program_build_date)
    program_shortdesc = __import__("__main__").__doc__.split("\n")[1]
    program_license = """%s

  Created by J. Buchhammer on %s.
  Copyright 2016 ProfitBricks GmbH. All rights reserved.

  Licensed under the Apache License 2.0
  http://www.apache.org/licenses/LICENSE-2.0

  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
""" % (
        program_shortdesc,
        str(__date__),
    )
    # Setup argument parser
    parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
    parser.add_argument("-u", "--user", dest="user", help="the login name")
    parser.add_argument("-p", "--password", dest="password", help="the login password")
    parser.add_argument("-L", "--Login", dest="loginfile", default=None, help="the login file to use")
    parser.add_argument("-i", "--infile", dest="infile", default=None, required=True, help="the input file name")
    parser.add_argument("-D", "--DCname", dest="dcname", default=None, help="new datacenter name")
    # TODO: add/overwrite image password for creation
    #    parser.add_argument('-P', '--imagepassword', dest='imgpassword',
    #                        default=None, help='the image password')
    parser.add_argument(
        "-v", "--verbose", dest="verbose", action="count", default=0, help="set verbosity level [default: %(default)s]"
    )
    parser.add_argument("-V", "--version", action="version", version=program_version_message)

    # Process arguments
    args = parser.parse_args()
    global verbose
    verbose = args.verbose

    if verbose > 0:
        print("Verbose mode on")
        print("start {} with args {}".format(program_name, str(args)))

    (user, password) = getLogin(args.loginfile, args.user, args.password)
    if user is None or password is None:
        raise ValueError("user or password resolved to None")
    pbclient = ProfitBricksService(user, password)

    usefile = args.infile
    print("read dc from {}".format(usefile))
    dcdef = read_dc_definition(pbclient, usefile)
    if verbose > 0:
        print("using DC-DEF {}".format(json.dumps(dcdef)))

    # setup dc:
    #     + create empty dc
    #     + create volumes (unattached), map uuid to servers (custom dict)
    #     + create servers
    #     + create nics
    #     + attach volumes

    if "custom" in dcdef and "id" in dcdef["custom"]:
        dc_id = dcdef["custom"]["id"]
        print("using existing DC w/ id {}".format(str(dc_id)))
    else:
        if args.dcname is not None:
            print("Overwrite DC name w/ '{}'".format(args.dcname))
            dcdef["properties"]["name"] = args.dcname
        dc = getDatacenterObject(dcdef)
        # print("create DC {}".format(str(dc)))
        response = pbclient.create_datacenter(dc)
        dc_id = response["id"]
        if "custom" not in dcdef:
            dcdef["custom"] = dict()
        dcdef["custom"]["id"] = dc_id
        result = wait_for_request(pbclient, response["requestId"])
        print("wait loop returned {}".format(result))
        tmpfile = usefile + ".tmp_postdc"
        write_dc_definition(pbclient, dcdef, tmpfile)

    requests = []
    print("create Volumes {}".format(str(dc)))
    # we do NOT consider dangling volumes, only server-attached ones
    for server in dcdef["entities"]["servers"]["items"]:
        print("- server {}".format(server["properties"]["name"]))
        if "volumes" not in server["entities"]:
            print(" server {} has no volumes".format(server["properties"]["name"]))
            continue
        for volume in server["entities"]["volumes"]["items"]:
            if "custom" in volume and "id" in volume["custom"]:
#.........这里部分代码省略.........
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:pb_createDatacenter.py

示例10: TestDatacenter

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_datacenter [as 别名]
class TestDatacenter(unittest.TestCase):
    def setUp(self):
        self.datacenter = ProfitBricksService(
            username='username', password='password')

    def test_get_all(self):
        datacenters = self.datacenter.list_datacenters()

        self.assertEqual(len(datacenters), 4)
        self.assertEqual(datacenters['items'][0]['id'], datacenter_id)
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['name'], 'datacenter1')
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['description'], 'Description of my DC')
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['location'], 'de/fkb')
        # self.assertEqual(
        #     datacenters['items'][0]['properties']['version'], 4)

    def test_get(self):
        datacenter = self.datacenter.get_datacenter(
            datacenter_id=datacenter_id)

        self.assertEqual(datacenter['id'], datacenter_id)
        self.assertEqual(datacenter['properties']['name'], 'datacenter1')
        self.assertEqual(datacenter['properties']['description'], 'Description of my DC')
        self.assertEqual(datacenter['properties']['version'], 4)
        self.assertEqual(datacenter['properties']['location'], 'de/fkb')

    def test_delete(self):
        datacenter = self.datacenter.delete_datacenter(
            datacenter_id=datacenter_id)

        self.assertTrue(datacenter)

    def test_update(self):
        datacenter = self.datacenter.update_datacenter(
            datacenter_id=datacenter_id,
            name='Partially updated datacenter name')

        self.assertEqual(datacenter['id'], datacenter_id)
        self.assertEqual(datacenter['properties']['name'], 'datacenter1')
        self.assertEqual(datacenter['properties']['description'], 'Description of my DC')
        self.assertEqual(datacenter['properties']['version'], 4)
        self.assertEqual(datacenter['properties']['location'], 'de/fkb')

    def test_create_simple(self):
        i = Datacenter(
            name='datacenter1',
            description='My New Datacenter',
            location='de/fkb'
            )

        response = self.datacenter.create_datacenter(datacenter=i)

        self.assertEqual(response['id'], datacenter_id)
        self.assertEqual(response['properties']['name'], 'My New Datacenter')
        self.assertEqual(response['properties']['description'], 'Production environment')
        self.assertEqual(response['properties']['version'], 4)
        self.assertEqual(response['properties']['location'], 'de/fkb')

    def test_create_complex(self):
        """
        Creates a complex Datacenter in a single request.

        """
        fwrule1 = FirewallRule(
            name='Open SSH port',
            protocol='TCP',
            source_mac='01:23:45:67:89:00',
            port_range_start=22
            )

        fwrule2 = FirewallRule(
            name='Allow PING',
            protocol='ICMP',
            icmp_type=8,
            icmp_code=0
            )

        fw_rules = [fwrule1, fwrule2]

        nic1 = NIC(
            name='nic1',
            ips=['10.2.2.3'],
            dhcp='true',
            lan=1,
            firewall_active=True,
            firewall_rules=fw_rules
            )

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

#.........这里部分代码省略.........
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_datacenter.py


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