-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_network.py
More file actions
executable file
·96 lines (79 loc) · 3.21 KB
/
Copy pathadd_network.py
File metadata and controls
executable file
·96 lines (79 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/python
from ovirtsdk.api import API
from ovirtsdk.xml import params
VERSION = params.Version(major='3', minor='5')
URL = 'https://rhevm.example.com/ovirt-engine/api'
CA = '/etc/pki/ovirt-engine/ca.pem'
USERNAME = 'admin@internal'
PASSWORD = 'paSSwoRD'
HOST_NAME = 'rhevh1'
IP_ADDRESS = '192.168.100.11'
MOVE_IP = '192.168.101.11'
NETMASK = '255.255.255.0'
GATEWAY = '192.168.100.1'
try:
api = API(url=URL, username=USERNAME, password=PASSWORD, ca_file=CA)
print "Connected to %s successfully!" % api.get_product_info().name
except Exception as err:
print "Connection failed: %s" % err
nic0 = params.HostNIC(network=params.Network(name='rhevm'),
name='eth0',
boot_protocol='static',
ip=params.IP(address=IP_ADDRESS,
netmask=NETMASK,
gateway=GATEWAY),
override_configuration=False)
nic1 = params.HostNIC(name='eth1',
network=params.Network(),
boot_protocol='none',
ip=params.IP(address=None,
netmask=None,
gateway=None))
nic2 = params.HostNIC(name='eth2',
network=params.Network(),
boot_protocol='none',
ip=params.IP(address=None,
netmask=None,
gateway=None))
# bond
bond0 = params.Bonding(slaves=params.Slaves(host_nic=[nic1, nic2]),
options=params.Options(option=[
params.Option(name='miimon', value='100'),
params.Option(name='mode', value='1'),
params.Option(name='primary', value='eth1')
]))
# management network on top of the bond
backendNetwork = params.HostNIC(name='bond0',
boot_protocol='none',
override_configuration=True,
bonding=bond0)
# Now apply the rhevm network configuration
try:
host = api.hosts.get(HOST_NAME)
host.nics.setupnetworks(params.Action(force=False,
check_connectivity=True,
host_nics=params.HostNics(host_nic=[
nic0, backendNetwork])))
except Exception as err:
print "Setup Network failed: %s" % err
# Finally add the labels
try:
host.nics.get('bond0').labels.add(params.Label(id='Backend'))
except Exception as err:
print "Add Label failed: %s" % err
# This only works in case a Virtual Network
# with VLAN ID 110 gets assigned with the Label 'Backend'.
# This Network is not defined in here.
try:
nic = host.nics.get(name='bond0.110')
nic.set_boot_protocol('static')
nic.set_ip(params.IP(address=MOVE_IP,
netmask=NETMASK,
gateway=None))
nic.update()
# Also save the networkconfig to the host
# Otherwise there will be an "action marker"
# in the Web-UI telling to Save the network
host.commitnetconfig()
except Exception as err:
print "Setting IP failed: %s" % err