def dump_vps_info(vps): ip = vps.ipv4 is not None and int2ip(vps.ipv4) or None ip_inter = vps.ipv4_inter is not None and int2ip( vps.ipv4_inter) or None netmask = vps.ipv4_netmask is not None and int2ip( vps.ipv4_netmask) or None gateway = vps.ipv4_gateway is not None and int2ip( vps.ipv4_gateway) or None if vps.state is not None: state = "%s(%s)" % (vps.state, vps_const.VPS_STATE2CN[vps.state]) else: state = None return "host_id %s, id %s, state %s, os %s, cpu %s, ram %sM, hd %sG, ip %s, netmask %s, gateway %s, inter_ip:%s, bandwidth:%s" % ( vps.host_id, vps.id, state, vps.os, vps.cpu, vps.ram, vps.hd, ip, netmask, gateway, ip_inter, vps.bandwidth, )
def setup_vps(self, xenvps, vps): xenvps.setup( os_id=vps.os, vcpu=vps.cpu, mem_m=vps.ram, disk_g=vps.hd, root_pw=vps.password, ip=int2ip(vps.ipv4), netmask=int2ip(vps.ipv4_netmask), gateway=int2ip(vps.ipv4_gateway), )
def dump_vps_info (vps): ip = vps.ipv4 is not None and int2ip (vps.ipv4) or None ip_inter = vps.ipv4_inter is not None and int2ip (vps.ipv4_inter) or None netmask = vps.ipv4_netmask is not None and int2ip (vps.ipv4_netmask) or None gateway = vps.ipv4_gateway is not None and int2ip (vps.ipv4_gateway) or None if vps.state is not None: state = "%s(%s)" % (vps.state, vps_const.VPS_STATE2CN[vps.state]) else: state = None return "host_id %s, id %s, state %s, os %s, cpu %s, ram %sM, hd %sG, ip %s, netmask %s, gateway %s, inter_ip:%s, bandwidth:%s" % ( vps.host_id, vps.id, state, vps.os, vps.cpu, vps.ram, vps.hd, ip, netmask, gateway, ip_inter, vps.bandwidth, )
def run_server (queue_dict): # server = zthrift.server.get_server_nonblock (saas.VPS, DummyHandler (queue_dict)) # return server.serve () zthrift.server.server (saas.VPS, DummyHandler (queue_dict), port=conf.SAAS_PORT + 1, allowed_ips=["119.254.32.166", "127.0.0.1"]) print "server exit ?" if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) queue_dict = get_queue_dict () th = threading.Thread(target=run_server, args=(queue_dict,)) th.setDaemon(1) th.start () time.sleep (2) transport, client = get_client (saas.VPS, host="127.0.0.1", port=conf.SAAS_PORT + 1) transport.open () try: vps = client.vps (1) print "id", vps.id, "os", vps.os, "cpu", vps.cpu, "ram", vps.ram, "hd", vps.hd, \ "ip", int2ip (vps.ipv4), "netmask", int2ip (vps.ipv4_netmask), "gateway", int2ip (vps.ipv4_gateway), \ "pw", vps.password finally: transport.close () # unittest.main () # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 :
def setup_vps (self, xenvps, vps): xenvps.setup (os_id=vps.os, vcpu=vps.cpu, mem_m=vps.ram, disk_g=vps.hd, root_pw=vps.password, ip=int2ip (vps.ipv4), netmask=int2ip (vps.ipv4_netmask), gateway=int2ip (vps.ipv4_gateway), )