Пример #1
0
    def CreateVmByCheckingDatabase(self):
        timeval = 5
        vms = [ 
                { "vmid": 100, "groupid": 1, "vmsubid": 1, "ownerid": "1", "vmtype": "ubuntu", 
                    "config_cpu": "1", "config_memory": "1024", "config_disk": "40", "config_lifetime": "192" },
                { "vmid": 101, "groupid": 2, "vmsubid": 1, "ownerid": "1", "vmtype": "apache", 
                    "config_cpu": "2", "config_memory": "256", "config_disk": "20", "config_lifetime": "192" },
                { "vmid": 102, "groupid": 3, "vmsubid": 1, "ownerid": "1", "vmtype": "hadoop", 
                    "config_cpu": "3", "config_memory": "2048", "config_disk": "80", "config_lifetime": "192" },
                { "vmid": 103, "groupid": 3, "vmsubid": 2, "ownerid": "1", "vmtype": "hadoop", 
                    "config_cpu": "4", "config_memory": "2048", "config_disk": "80", "config_lifetime": "192" }
            ]

        vmseq = [ vms[0], None, None, vms[1], None, vms[2], vms[3]] # every 5 secs
        i = 0

        print("start detect in 3 secs")
        time.sleep(1)
        print("start detect in 2 secs")
        time.sleep(1)
        print("start detect in 1 secs")
        time.sleep(1)

        while 1 :
            if i < len(vmseq) :
                vm = vmseq[i]
                i = i + 1
                if vm != None :
                    print("detect new vm create from user!")
                    dir(vm)
                    req = Message.CreateVmByRackReq( vmid=vm['vmid'], groupid=vm['groupid'], vmsubid=vm['vmsubid'], ownerid=vm['ownerid'],
                                                  vmtype=vm['vmtype'], config_cpu=vm['config_cpu'], config_memory=vm['config_memory'], 
                                                  config_disk=vm['config_disk'], config_lifetime=vm['config_lifetime'])
                    destRackAddress = ("140.112.28.240", 7001)
                    Client.sendonly_message( destRackAddress, req )

            time.sleep(timeval)
        return
        db_host = "140.112.28.240"
        db_name = "roystonea_2012"
        db_user = "******"
        db_password = "******"
        timeval = 5
        while 1:
            con = mdb.connect(db_host, db_user, db_password, db_name)
            cur = con.cursor(mdb.cursors.DictCursor)
            cur.execute( 'SELECT * FROM vm WHERE vmstatus = "prepare_to_starts"a')
            
            rows = cur.fetchall()
            time.sleep(timeval)
Пример #2
0
    def databaseSubsystem(self):
        try:
            con = mdb.connect(self.db_host, self.db_account, self.db_password,
                              self.db_name)

            while True:
                cur = con.cursor(mdb.cursors.DictCursor)
                cur.execute(
                    'SELECT * FROM vm WHERE state = "prepare_to_start"')

                rows = cur.fetchall()
                for row in rows:
                    try:
                        msg = Message.DatabaseSubsystemCreateVMreq(
                            vm_id=row['vm_id'],
                            group_num=row['group_num'],
                            vm_num=row['vm_num'],
                            vm_name=row['vm_name'],
                            owner=row['owner'],
                            type=row['type'],
                            cpu=row['cpu'],
                            mem=row['mem'],
                            disk=row['disk'],
                        )

                        # use %s to not change data type
                        ###cur.execute( 'UPDATE vm SET state = "pending" WHERE vm_id = "%s"' %(row['vm_id']) )

                        # Cluster's address
                        address = 'roystonea01', 9500
                        Client.sendonly_message(address, msg)

                    except socket.error as e:
                        print 'socket error'
                        sleep(5)

                sleep(5)

        except mdb.Error, e:
            print 'Error %d: %s' % (e.args[0], e.args[1])
            sys.exit(1)
Пример #3
0
    def databaseSubsystem(self):
        try:
            con = mdb.connect(self.db_host, self.db_account, self.db_password, self.db_name)

            while True:
                cur = con.cursor(mdb.cursors.DictCursor)
                cur.execute('SELECT * FROM vm WHERE state = "prepare_to_start"')
                   
                rows = cur.fetchall()
                for row in rows:
                    try:
                        msg = Message.DatabaseSubsystemCreateVMreq(
                                vm_id = row['vm_id'],
                                group_num = row['group_num'],
                                vm_num = row['vm_num'],
                                vm_name = row['vm_name'],
                                owner = row['owner'],
                                type = row['type'],
                                cpu = row['cpu'],
                                mem = row['mem'],
                                disk = row['disk'],
                                )
                        
                        # use %s to not change data type
                        ###cur.execute( 'UPDATE vm SET state = "pending" WHERE vm_id = "%s"' %(row['vm_id']) )
                        
                        # Cluster's address
                        address = 'roystonea01', 9500
                        Client.sendonly_message(address, msg)
                        
                    except socket.error as e:
                        print 'socket error'
                        sleep(5)
                
                sleep(5)
        
        except mdb.Error, e:
            print 'Error %d: %s' %(e.args[0], e.args[1])
            sys.exit(1)
Пример #4
0
    def CreateVmByCheckingDatabase(self):
        timeval = 5
        vms = [{
            "vmid": 100,
            "groupid": 1,
            "vmsubid": 1,
            "ownerid": "1",
            "vmtype": "ubuntu",
            "config_cpu": "1",
            "config_memory": "1024",
            "config_disk": "40",
            "config_lifetime": "192"
        }, {
            "vmid": 101,
            "groupid": 2,
            "vmsubid": 1,
            "ownerid": "1",
            "vmtype": "apache",
            "config_cpu": "2",
            "config_memory": "256",
            "config_disk": "20",
            "config_lifetime": "192"
        }, {
            "vmid": 102,
            "groupid": 3,
            "vmsubid": 1,
            "ownerid": "1",
            "vmtype": "hadoop",
            "config_cpu": "3",
            "config_memory": "2048",
            "config_disk": "80",
            "config_lifetime": "192"
        }, {
            "vmid": 103,
            "groupid": 3,
            "vmsubid": 2,
            "ownerid": "1",
            "vmtype": "hadoop",
            "config_cpu": "4",
            "config_memory": "2048",
            "config_disk": "80",
            "config_lifetime": "192"
        }]

        vmseq = [vms[0], None, None, vms[1], None, vms[2],
                 vms[3]]  # every 5 secs
        i = 0

        print("start detect in 3 secs")
        time.sleep(1)
        print("start detect in 2 secs")
        time.sleep(1)
        print("start detect in 1 secs")
        time.sleep(1)

        while 1:
            if i < len(vmseq):
                vm = vmseq[i]
                i = i + 1
                if vm != None:
                    print("detect new vm create from user!")
                    dir(vm)
                    req = Message.CreateVmByRackReq(
                        vmid=vm['vmid'],
                        groupid=vm['groupid'],
                        vmsubid=vm['vmsubid'],
                        ownerid=vm['ownerid'],
                        vmtype=vm['vmtype'],
                        config_cpu=vm['config_cpu'],
                        config_memory=vm['config_memory'],
                        config_disk=vm['config_disk'],
                        config_lifetime=vm['config_lifetime'])
                    destRackAddress = ("140.112.28.240", 7001)
                    Client.sendonly_message(destRackAddress, req)

            time.sleep(timeval)
        return
        db_host = "140.112.28.240"
        db_name = "roystonea_2012"
        db_user = "******"
        db_password = "******"
        timeval = 5
        while 1:
            con = mdb.connect(db_host, db_user, db_password, db_name)
            cur = con.cursor(mdb.cursors.DictCursor)
            cur.execute(
                'SELECT * FROM vm WHERE vmstatus = "prepare_to_starts"a')

            rows = cur.fetchall()
            time.sleep(timeval)