#!/usr/bin/env python # -*- coding: utf-8 -*- # bson.son.SON an # kpov_random_helpers should be imported by add_assignment.py # OrderedDict = SON instructions = { "si":""" Ustvari dva navidezna računalnika - imenujmo ju SimpleArbiterDhcpGW in Student. Za računalnik SimpleArbiterDhcpGW uporabite sliko diska, poimenovano SimpleArbiterDhcpGW. Na računalniku Student ustvarite uporabnika z uporabniškim imenom {peer_user}. Poskrbite, da se bo v sporočilu, ki se ob prijavi izpiše na računalniku Student, pojavil niz "{niz}". Temu sporočilu v angleščini rečemo "message of the day" - MOTD. IP navideznega računalnika Student ter geslo za {peer_user} nastavite sami. Ocenjevalni program pričakuje, da se bo ob koncu prijave pojavila ukazna vrstica oblike uporabnisko_ime@ime_racunalnika:~$ . Pazite, da se bo takšna vrstica pojavila šele po nizu, ki ste ga dobili v teh navodilih. """, 'en':""" Create two virtual machines - named SimpleArbiterDhcpGW and Student. For the 'SimpleArbiterDhcpGW', use disc image named SimpleArbiterDhcpGW. On Student, create a user with the username {peer_user}. Set the message of the day (MOTD) on Student to "{niz}". This is the message which is displayed when you log in. Set the IP of Student and the password for {peer_user} yourself. The grading system expects that at the end of login, a prompt similar to username@name_of_computer:~$ appears. Make sure that this line shows up only after the string you got in these instructions. """ } computers = { 'SimpleArbiterDhcpGW': { 'disks': [ { 'name': 'simpleArbiterDhcpGW', }, ], 'flavor': 'm1.tiny', 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}], 'config_drive': True, 'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"} }, 'Student': { 'disks': [ { 'name': 'student-console', } ], 'flavor': 'm1.tiny', 'network_interfaces': [{'network': 'net1'}], 'config_drive': True, 'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"} } } networks = { 'net1': {'public': False}, 'test-net': {'public': True} } params_meta = { 'peer_ip': {'descriptions': {'si': 'IP računalnika', 'en':'IP'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False}, 'peer_user': {'descriptions': {'si': 'ime uporabnika', 'en':'Username'}, 'w': False, 'public': True, 'type': 'username', 'generated': True}, 'peer_passwd': {'descriptions': {'si': 'geslo uporabnika', 'en': 'Password'}, 'w': True, 'public': True, 'type': 'alnumstr', 'generated': False}, 'niz': {'descriptions':{'si': 'niz, ki naj se v motd pokaže', 'en': 'The string which should be displayed in the MOTD'}, 'w': False, 'public': True, 'type': 'short_text', 'generated': True}, } def task(peer_ip, peer_user, peer_passwd, niz): "Check whether ssh works" from pexpect import pxssh import pexpect # return {"hello": 'kitty'} results = dict() s = pxssh.pxssh() #TODO (polz): tole bi utegnilo delovati http://pexpect.sourceforge.net/pxssh.html. Testirajte s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False) # print s.before # s.prompt() #Ce na serverju iz datoteke /var/run/motd.dynamic pobrisemo znak '#' bi moralo delovati. # temp = s.before # print everything before the prompt. #TODO (polz): tole ni pravi pristop. Problem je bil v tem, da pxssh ni prav zaznal, kdaj je prijavljen. Glej link zgoraj. results['motd'] = s.before # print everything before the prompt. return results # def gen_params(user_id, params_meta): return kpov_random_helpers.default_gen(user_id, params_meta) def task_check(results, params): #print task_url #print params #print results niz = params['niz'] score = 0 hints = [] if (results['motd'].find(niz) > -1): score += 10 return score, hints def prepare_disks(templates, task_params, global_params): write_default_config(templates['simpleArbiterDhcpGW'], global_params)