本文整理汇总了Python中profitbricks.client.ProfitBricksService.list_nics方法的典型用法代码示例。如果您正苦于以下问题:Python ProfitBricksService.list_nics方法的具体用法?Python ProfitBricksService.list_nics怎么用?Python ProfitBricksService.list_nics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profitbricks.client.ProfitBricksService
的用法示例。
在下文中一共展示了ProfitBricksService.list_nics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import list_nics [as 别名]
#.........这里部分代码省略.........
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('-d', '--datacenterid', dest='datacenterid',
required=True, default=None,
help='datacenter of the new server')
parser.add_argument('-l', '--lanid', dest='lanid', required=True,
default=None, help='LAN of the new server')
parser.add_argument('-n', '--name', dest='servername',
default="SRV_"+datetime.now().isoformat(),
help='name of the new server')
parser.add_argument('-c', '--cores', dest='cores', type=int,
default=2, help='CPU cores')
parser.add_argument('-r', '--ram', dest='ram', type=int, default=4,
help='RAM in GB')
parser.add_argument('-s', '--storage', dest='storage', type=int,
default=4, help='storage in GB')
parser.add_argument('-b', '--boot', dest='bootdevice', default="HDD",
help='boot device')
parser.add_argument('-i', '--imageid', dest='imageid', default=None,
help='installation image')
parser.add_argument('-P', '--imagepassword', dest='imgpassword',
default=None, help='the image password')
parser.add_argument('-v', '--verbose', dest="verbose", action="count",
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
dc_id = args.datacenterid
lan_id = args.lanid
servername = args.servername
if verbose > 0:
print("Verbose mode on")
print("start {} with args {}".format(program_name, str(args)))
# Test images (location de/fra)
# CDROM: 7fc885b3-c9a6-11e5-aa10-52540005ab80 # debian-8.3.0-amd64-netinst.iso
# HDD: 28007a6d-c88a-11e5-aa10-52540005ab80 # CentOS-7-server-2016-02-01
hdimage = args.imageid
cdimage = None
if args.bootdevice == "CDROM":
hdimage = None
cdimage = args.imageid
print("using boot device {} with image {}"
.format(args.bootdevice, args.imageid))
(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)
first_nic = NIC(name="local", ips=[], dhcp=False, lan=lan_id)
volume = Volume(name=servername+"-Disk", size=args.storage,
image=hdimage, image_password=args.imgpassword)
server = Server(name=servername, cores=args.cores, ram=args.ram*1024,
create_volumes=[volume], nics=[first_nic],
boot_cdrom=cdimage)
print("creating server..")
if verbose > 0:
print("SERVER: {}".format(str(server)))
response = pbclient.create_server(dc_id, server)
print("wait for provisioning..")
wait_for_request(pbclient, response["requestId"])
server_id = response['id']
print("Server provisioned with ID {}".format(server_id))
nics = pbclient.list_nics(dc_id, server_id, 1)
# server should have exactly one nic, but we only test empty nic list
if len(nics['items']) == 0:
raise CLIError("No NICs found for newly created server {}"
.format(server_id))
nic0 = nics['items'][0]
if verbose > 0:
print("NIC0: {}".format(str(nic0)))
(nic_id, nic_mac) = (nic0['id'], nic0['properties']['mac'])
print("NIC of new Server has ID {} and MAC {}".format(nic_id, nic_mac))
print("{} finished w/o errors".format(program_name))
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
示例2: ProfitBricksService
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import list_nics [as 别名]
"""List NICs
"""
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')
nics = client.list_nics(
datacenter_id=datacenter_id,
server_id=server_id)
for n in nics['items']:
print(n['properties']['name'])
"""Create NIC
"""
from profitbricks.client import ProfitBricksService, NIC
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',
示例3: TestNIC
# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import list_nics [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(
#.........这里部分代码省略.........