· 4 years ago · Aug 13, 2021, 07:06 PM
1# This script will mass create virtual mac addresses on OVH servers owned by North Networking
2
3import json
4import ovh
5import time
6
7# Service name
8ServiceName = "ns545596.ip-xxx-xxx-xxx.net"
9
10# Ipaddress variable, change as needed
11IpAdr = "xxx.xxx.xxx."
12IpSuffix = xxx
13
14# Virtual Mac Name variable
15vMacName = "vm"
16vMacNum = 16
17
18# How many IP addresses to loop through?
19NumOfIP = 16
20count = 0
21concurrentTasks = 0
22
23while count < NumOfIP:
24
25 # Instanciate an OVH Client.
26 # You can generate new credentials with full access to your account on
27 # the token creation page
28 client = ovh.Client(
29 endpoint='ovh-eu', # Endpoint of API OVH Europe (List of available endpoints)
30 application_key='xxxxx', # Application Key
31 application_secret='xxxxx', # Application Secret
32 consumer_key='xxxxx', # Consumer Key
33 )
34
35 result = client.post('/dedicated/server/' + ServiceName +'/virtualMac',
36 ipAddress=IpAdr + str(IpSuffix), #Ip address to link with this virtualMac (type: ipv4)
37 type='ovh', #vmac address type (type: dedicated.server.VmacTypeEnum)
38 virtualMachineName=vMacName + str(vMacNum), #Friendly name of your Virtual Machine behind this IP/MAC (type: string)
39 )
40 # Update count and IP count
41 vMacNum += 1
42 IpSuffix += 1
43 count += 1
44 concurrentTasks += 1
45
46 if concurrentTasks >= 5:
47 concurrentTasks = 0
48 print("Added maximum allowed concurrent tasks, sleeping for a minute.")
49 time.sleep(60)
50 print("Continuing with task.")
51
52 # Pretty print
53 print (result)
54
55print("Finished creating vMacs for all IP addresses!")