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


Python ProfitBricksService.create_nic方法代码示例

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


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

示例1: TestLan

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

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_nic [as 别名]
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'

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

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

response = client.create_nic(
    datacenter_id=datacenter_id,
    server_id=server_id,
    nic=i)

"""Create NIC with FirewallRules
"""
from profitbricks.client import ProfitBricksService, FirewallRule, NIC

datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'
nic_id = '<NIC-ID>'

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

fwrule1 = FirewallRule(
    name='Open SSH port',
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:34,代码来源:nic_examples.py

示例3: TestServer

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

示例4: main

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_nic [as 别名]

#.........这里部分代码省略.........
            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']
            print("use existing DC {} in location {}"
                  .format(dc['properties']['name'], location))

        # check if images exist
        for disk in metadata.disks:
            disk_name = disk['file']
            images = get_disk_image_by_name(pbclient, location, disk_name)
            if len(images) == 0:
                raise ValueError("No HDD image with name '{}' found in location {}"
                                 .format(disk_name, location))
            if len(images) > 1:
                raise ValueError("Ambigous image name '{}' in location {}"
                                 .format(disk_name, location))
            disk['image'] = images[0]['id']

        # now we're ready to create the VM
        # Server
        server = Server(name=metadata.name,
                        cores=metadata.cpus, ram=metadata.ram)
        print("create server {}".format(str(Server)))
        response = pbclient.create_server(dc_id, server)
        srv_id = response['id']
        result = wait_for_request(pbclient, response['requestId'])
        print("wait loop returned {}".format(str(result)))
        # NICs (note that createing LANs may be implicit)
        for nic in metadata.nics:
            dcnic = NIC(name=nic['nic'], lan=nic['lanid'])
            print("create NIC {}".format(str(dcnic)))
            response = pbclient.create_nic(dc_id, srv_id, dcnic)
            nic_id = response['id']
            result = wait_for_request(pbclient, response['requestId'])
            print("wait loop returned {}".format(str(result)))
            response = pbclient.get_nic(dc_id, srv_id, nic_id, 2)
            mac = response['properties']['mac']
            print("dcnic has MAC {} for {}".format(mac, nic_id))
        # end for(nics)
        # Volumes (we use the image name as volume name too
        requests = []
        for disk in metadata.disks:
            dcvol = Volume(name=disk['file'], size=disk['capacity'],
                           image=disk['image'],
                           licence_type=metadata.licenseType)
            print("create Volume {}".format(str(dcvol)))
            response = pbclient.create_volume(dc_id, dcvol)
            requests.append(response['requestId'])
            disk['volume_id'] = response['id']
        # end for(disks)
        if len(requests) != 0:
            result = wait_for_requests(pbclient, requests, initial_wait=10, scaleup=15)
            print("wait loop returned {}".format(str(result)))
        for disk in metadata.disks:
            print("attach volume {}".format(disk))
            response = pbclient.attach_volume(dc_id, srv_id, disk['volume_id'])
            result = wait_for_request(pbclient, response['requestId'])
            print("wait loop returned {}".format(str(result)))
        # end for(disks)

        print("import of VM succesfully finished")
        return 0

    except KeyboardInterrupt:
        ### handle keyboard interrupt ###
        return 0
    except Exception:
        traceback.print_exc()
        sys.stderr.write("\n" + program_name + ":  for help use --help\n")
        return 2
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:104,代码来源:pb_importVM.py

示例5: TestLan

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

示例6: TestNIC

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

    def test_list_nics(self):
        nics = self.nic.list_nics(
            datacenter_id=datacenter_id,
            server_id=server_id)

        self.assertEqual(len(nics), 4)
        self.assertEqual(nics['items'][0]['id'], nic_id)
        self.assertEqual(nics['items'][0]['properties']['name'], 'nic1')
        self.assertEqual(
            nics['items'][0]['properties']['mac'], 'AB:21:23:09:78:C2')
        self.assertEqual(nics['items'][0]['properties']['dhcp'], 'true')
        self.assertEqual(nics['items'][0]['properties']['lan'], 1)

    def test_get_nic(self):
        nic = self.nic.get_nic(
            datacenter_id=datacenter_id,
            server_id=server_id,
            nic_id=nic_id)

        self.assertEqual(nic['id'], nic_id)
        self.assertEqual(nic['properties']['name'], 'nic1')
        self.assertEqual(nic['properties']['mac'], 'AB:21:23:09:78:C2')
        self.assertEqual(nic['properties']['dhcp'], 'true')
        self.assertEqual(nic['properties']['lan'], 1)

    def test_delete_nic(self):
        nic = self.nic.delete_nic(
            datacenter_id=datacenter_id,
            server_id=server_id,
            nic_id=nic_id)

        self.assertTrue(nic)

    def test_update_nic(self):
        nic = self.nic.update_nic(
            datacenter_id=datacenter_id,
            server_id=server_id,
            nic_id=nic_id,
            ips=['10.2.2.3', '10.2.3.4'])

        self.assertEqual(nic['id'], nic_id)
        self.assertEqual(nic['properties']['name'], 'nic1')
        self.assertEqual(nic['properties']['mac'], 'AB:21:23:09:78:C2')
        self.assertEqual(nic['properties']['dhcp'], 'true')
        self.assertEqual(nic['properties']['lan'], 1)

    def test_create_complex(self):
        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]

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

        response = self.nic.create_nic(
            datacenter_id=datacenter_id,
            server_id=server_id, nic=i)

        self.assertEqual(response['id'], nic_id)
        self.assertEqual(response['properties']['name'], 'nic1')
        self.assertEqual(
            response['properties']['mac'], 'AB:21:23:09:78:C2')
        self.assertEqual(response['properties']['dhcp'], 'true')
        self.assertEqual(response['properties']['lan'], 1)
        self.assertListEqual(
            response['properties']['ips'], ['10.2.2.3'])

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

        response = self.nic.create_nic(
#.........这里部分代码省略.........
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_nic.py

示例7: main

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import create_nic [as 别名]

#.........这里部分代码省略.........
    requests = []
    print("create Servers {}".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 "custom" in server and "id" in server["custom"]:
            srv_id = server["custom"]["id"]
            print("using existing server w/ id {}".format(str(srv_id)))
        else:
            dcsrv = getServerObject(server)
            print("OBJ: {}".format(str(dcsrv)))
            response = pbclient.create_server(dc_id, dcsrv)
            server.update({"custom": {"id": response["id"]}})
            requests.append(response["requestId"])
    # end for(server)
    if len(requests) != 0:
        result = wait_for_requests(pbclient, requests, initial_wait=10, scaleup=15)
        print("wait loop returned {}".format(str(result)))
        tmpfile = usefile + ".tmp_postsrv"
        write_dc_definition(pbclient, dcdef, tmpfile)
    else:
        print("all servers existed already")

    # TODO: only do this if we have lan entities
    requests = []
    # Huuh, looks like we get unpredictable order for LANs!
    # Nope, order of creation determines the LAN id,
    # thus we better wait for each request
    print("create LANs {}".format(str(dc)))
    for lan in dcdef["entities"]["lans"]["items"]:
        print("- lan {}".format(lan["properties"]["name"]))
        dclan = getLANObject(lan)
        print("OBJ: {}".format(str(dclan)))
        response = pbclient.create_lan(dc_id, dclan)
        lan.update({"custom": {"id": response["id"]}})
        result = wait_for_request(pbclient, response["requestId"])
        print("wait loop returned {}".format(str(result)))
    # end for(lan)
    tmpfile = usefile + ".tmp_postlan"
    write_dc_definition(pbclient, dcdef, tmpfile)

    requests = []
    # Attention:
    # NICs appear in OS in the order, they are created.
    # But DCD rearranges the display by ascending MAC addresses.
    # This does not change the OS order.
    # MAC may not be available from create response,
    # thus we wait for each request :-(
    print("create NICs {}".format(str(dc)))
    for server in dcdef["entities"]["servers"]["items"]:
        print("- server {}".format(server["properties"]["name"]))
        srv_id = server["custom"]["id"]
        if "nics" not in server["entities"]:
            print(" server {} has no NICs".format(server["properties"]["name"]))
            continue
        macmap = dict()
        for nic in server["entities"]["nics"]["items"]:
            dcnic = getNICObject(nic)
            response = pbclient.create_nic(dc_id, srv_id, dcnic)
            # print("dcnic response {}".format(str(response)))
            # mac = response['properties']['mac'] # we don't get it here !?
            nic_id = response["id"]
            result = wait_for_request(pbclient, response["requestId"])
            print("wait loop returned {}".format(str(result)))
            response = pbclient.get_nic(dc_id, srv_id, nic_id, 2)
            mac = response["properties"]["mac"]
            print("dcnic has MAC {} for {}".format(mac, nic_id))
            macmap[mac] = nic_id
        # end for(nic)
        macs = sorted(macmap)
        print("macs will be displayed by DCD in th following order:")
        for mac in macs:
            print("mac {} -> id{}".format(mac, macmap[mac]))
    # end for(server)
    tmpfile = usefile + ".tmp_postnic"
    write_dc_definition(pbclient, dcdef, tmpfile)

    requests = []
    # don't know if we get a race here too, so better wait for each request :-/
    print("attach volumes {}".format(str(dc)))
    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
        srv_id = server["custom"]["id"]
        for volume in server["entities"]["volumes"]["items"]:
            print("OBJ: {}".format(volume["properties"]["name"]))
            response = pbclient.attach_volume(dc_id, srv_id, volume["custom"]["id"])
            result = wait_for_request(pbclient, response["requestId"])
            print("wait loop returned {}".format(str(result)))
        # end for(volume)
    # end for(server)
    tmpfile = usefile + ".tmp_postatt"
    write_dc_definition(pbclient, dcdef, tmpfile)

    # TODO: do we need to set boot volume for each server?
    # looks like it's working without

    return 0
开发者ID:fbrehm,项目名称:profitbricks-sdk-python,代码行数:104,代码来源:pb_createDatacenter.py


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