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
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#coding:utf-8
import os
import sys
import stat
import time
import string
import sunhpc
class Command(sunhpc.commands.add.host.command):
"""
Adds an interface to a host and sets the associated values
<arg type='string' name='host'>
Host name of machine
</arg>
<arg type='string' name='iface'>
The interface name on the host (e.g., 'eth0', 'eth1')
</arg>
<param type='string' name='iface'>
Can be used in place of the iface argument.
</param>
<param type='string' name='ip'>
The IP address to assign to the interface (e.g., '192.168.1.254')
</param>
<param type='string' name='subnet'>
The name of the subnet to assign to the interface (e.g., 'private')
</param>
<param type='string' name='name'>
The name to assign to the interface
</param>
<param type='string' name='mac'>
The MAC address of the interface (e.g., '00:11:22:33:44:55')
</param>
<example cmd='add host interface compute-0-0 eth1 ip=192.168.1.2 subnet=private name=fast-0-0'>
</example>
<example cmd='add host interface compute-0-0 iface=eth1 ip=192.168.1.2 subnet=private name=fast-0-0'>
same as above
</example>
<related>set host interface iface</related>
<related>set host interface ip</related>
<related>set host interface mac</related>
<related>set host interface name</related>
<related>set host interface subnet</related>
"""
def run(self, params, args):
(args, iface) = self.fillPositionalArgs(('iface',))
hosts = self.getHostnames(args)
if not iface:
self.abort('missing iface')
if len(hosts) != 1:
self.abort('must supply one host')
host = hosts[0]
#
# determine if this is an interface name or a MAC address
#
isMac = 0
m = iface.split(':')
if len(m) >= 6:
isMac = 1
rows = self.db.search("""select * from networks,nodes where
nodes.name='%s' and
(networks.device='%s' or networks.mac='%s') and
networks.node=nodes.id""" % (host, iface, iface))
if rows:
self.abort('interface "%s" exists' % iface)
if isMac:
self.db.execute("""insert into networks(node,mac)
values ((select id from nodes where name='%s'),
'%s')""" % (host, iface))
else:
self.db.execute("""insert into networks(node,device)
values ((select id from nodes where name='%s'),
'%s')""" % (host, iface))
for key in ['ip', 'mac', 'name', 'subnet']:
if key in params:
self.command('set.host.interface.%s' % key,
(host, iface, params[key]))
RollName = "base"
|