30 from cm.utils.exception
import CMException
32 sys.path.append(
'/usr/lib/cc1/')
33 os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"cm.settings")
35 from cm.models.node
import Node
36 from common.states
import node_states
38 raise CMException(
'node_cannot_import_model')
43 if [ -e /etc/apt/sources.list ] ; then
44 echo 'deb http://cc1.ifj.edu.pl/packages/ wheezy main #CC1' >> /etc/apt/sources.list
46 apt-get --yes --force-yes install cc1-node cc1-common cc1-common-networking
49 echo "NODE: Creating cc1 user"
50 python /usr/sbin/cc1_setup_user create
52 echo "NODE: Configuring node"
53 python /usr/sbin/cc1_node_configure configure "%(public_key)s"
57 echo TODO: ala ma kota
61 def add(address, username, transport, driver, suffix, cpu, memory, disk):
63 Node.objects.get(address=address)
64 raise CMException(
'node_exists')
69 node.address = address
72 node.transport = transport
73 node.username = username
76 node.memory_total = memory
78 node.state = node_states[
'offline']
86 node = Node.objects.get(id=node_id)
88 raise CMException(
'node_not_found')
90 public_key = open(
'/var/lib/cc1/.ssh/id_rsa.pub').read()
94 if distribution ==
'debian':
95 r = subprocess.call([
'ssh',
'-o',
'PasswordAuthentication=no',
'root@%s' % (node.address),
96 debian_script % {
'public_key': public_key}])
97 elif distribution ==
'redhat':
98 r = subprocess.call([
'ssh',
'-o',
'PasswordAuthentication=no',
'root@%s' % (node.address),
99 redhat_script % {
'public_key': public_key}])
101 raise CMException(
'node_not_implemented')
104 raise CMException(
'node_install')
115 node = Node.objects.get(id=node_id)
117 raise CMException(
'node_not_found')
120 sys.path.append(
'/etc/cc1/cm/')
123 raise CMException(
'node_config_invalid')
125 cm_ip =
'echo $SSH_CLIENT | cut -d " " -f 1'
126 r = subprocess.call([
'ssh',
128 '/var/lib/cc1/.ssh/id_rsa',
129 '%s@%s' % (node.username, node.address),
130 'sudo /usr/sbin/cc1_network_setup configure http://`%s`:8003/ %s %s' % (cm_ip,
','.join(interfaces), settings.OSPF_TOKEN)])
133 raise CMException(
'node_setup_networking')
135 r = subprocess.call([
'ssh',
137 '/var/lib/cc1/.ssh/id_rsa',
138 '%s@%s' % (node.username, node.address),
139 'sudo /usr/sbin/cc1_node_setup_libvirt configure %s %s %s %s %s' %
140 (node.address, node.username, node.transport, node.driver, node.suffix)])
142 raise CMException(
'node_setup_libvirt')
147 node = Node.objects.get(id=node_id)
149 raise CMException(
'node_not_found')
151 subprocess.call([
'ssh',
'-i',
'/var/lib/cc1/.ssh/id_rsa',
152 '%s@%s' % (node.username, node.address),
153 'sudo /etc/init.d/cc1-node restart'])
157 nodes = Node.objects.all()
159 if node.state != node_states[
'locked']:
160 node.state = node_states[
'offline']
164 if node.state != node_states[
'locked']:
165 subprocess.call([
'ssh',
'%s@%s' % (node.username, node.address),
'sudo /etc/init.d/cc1-node start'])
171 nodes = Node.objects.all()
173 nodes = Node.objects.filter(state=node_states[state]).all()
176 if node.state != node_states[
'locked']:
177 subprocess.call([
'ssh',
'%s@%s' % (node.username, node.address), cmd])
181 print "Not implemented!"
186 print "Not implemented!"