def create():
	name = request.args.get('name')
	inst = request.args.get('instance_type')
	img = request.args.get('image_id')
	vm = {}
	vm['name'] = name
	vm['instance_type'] = inst
	vm['image_id'] = img
	return jsonify(create_vm.create(vm))
Example #2
0
def create():
    name = request.args.get('name')
    inst = request.args.get('instance_type')
    img = request.args.get('image_id')
    vm = {}
    vm['name'] = name
    vm['instance_type'] = inst
    vm['image_id'] = img
    return jsonify(create_vm.create(vm))
def url_parse(server, url):
    print "details", vm_ki_info
    print url
    host_name = url
    if "?" in url:
        host_name, args = url.split("?")
    url_comps = host_name.split("/")
    print url_comps
    if "create" in url_comps and "vm" in url_comps:
        received_args = []
        arg_split = args.split("&")
        for i in xrange(0, 3):
            received_args.append((arg_split[i].split("="))[1])
        print received_args
        create_vm.create(server, received_args)
    elif "destroy" in url_comps and "vm" in url_comps:
        received_args = []
        arg_split = args.split("=")
        received_args.append(arg_split[1])
        destroy_vm.destroy(server, received_args)
        pass
    elif "query" in url_comps and "vm" in url_comps:
        received_args = int(args.split("=")[1])
        printing.vm_query(server, received_args)

    elif "query" in url_comps and "volume" in url_comps:
        received_args = int(args.split("=")[1])
        printing.volume_query(server, received_args)

    elif "types" in url_comps:
        printing.print_types(server)

    elif "list" in url_comps:
        # print "here"
        printing.print_images(server)

    elif "create" in url_comps and "volume" in url_comps:
        received_args = []
        arg_split = args.split("&")
        for i in xrange(0, 2):
            received_args.append((arg_split[i].split("="))[1])
        print received_args
        print "yayayayaya"
        create_volume.create(server, received_args)
        # main_file.create(server,received_args)

    elif "destroy" in url_comps and "volume" in url_comps:
        received_args = []
        arg_split = args.split("=")
        received_args.append(arg_split[1])
        destroy_volume.destroy(server, received_args)
        # main_file.destroy(server,received_args)
        pass

    elif "attach" in url_comps and "volume" in url_comps:
        received_args = []
        arg_split = args.split("&")
        for i in xrange(0, 2):
            received_args.append((arg_split[i].split("="))[1])
        print received_args
        print "yayayayaya"
        attach_volume.attach(server, received_args)

    elif "detach" in url_comps and "volume" in url_comps:
        received_args = []
        arg_split = args.split("=")
        received_args.append(arg_split[1])
        detach_vm.detach(server, received_args)
        pass
def request_create():
    vm = {}
    vm['name'] = request.args.get('name')
    vm['instance_type'] = request.args.get('instance_type')
    vm['image_id'] = request.args.get('image_id')
    return jsonify(create_vm.create(vm))
def get_create():
	vm={}
	vm['name']=request.args.get('name')
	vm['instance_type']=request.args.get('instance_type')
	vm['image_id']=request.args.get('image_id')
	return jsonify(create_vm.create(vm))
Example #6
0
	def do_GET(self):
		print self.path
		url=self.path
		if '/vm/create' in url:
			whattodo = url
			arguments = []
			arg_split = url.split('?')[1].split('&')
			for i in xrange(0,3):
				arguments.append((arg_split[i].split('='))[1])
			print arguments
			create_vm.create(self,arguments)
		elif '/vm/destroy' in url:
			print url.split('?')[1].split('=')[1]
			DelQueType.destroy(self,url.split('?')[1].split('=')[1])
		elif '/vm/query' in url:
			DelQueType.query(self,url.split('?')[1].split('=')[1])
		elif '/vm/types' in url:
			DelQueType.vmtypes(self)
		elif '/vm/image/list' in url:
			fn=resource_dis.image_id
			l=[]
			for x in fn:
				d={}
				d["id"]=x
				d["name"]=fn[x][2][0]
				l.append(d)
			p={}
			p["iamges"]=l
			self.wfile.write(json_out(p))
		elif '/volume/create' in url:
			global VOLUME_LIST
			url=self.path
			arg=self.path.split('?')
			volume_name = arg[1].split('&')[0].split('=')[1]
			volume_size = arg[1].split('&')[1].split('=')[1]
			actual_size = int(float(volume_size)*(1024**2))
			global rbdInstance
			rbdInstance.create(ioctx,str(volume_name),actual_size)
			os.system('sudo rbd map %s --pool %s --name client.admin'%(str(volume_name),str(POOL_NAME)));
			volume_id=len(VOLUME_LIST)
			VOLUME_LIST[int(volume_id)]=str(volume_name)
			print VOLUME_LIST
			self.wfile.write(json_out({"volumeid":volume_id}))

		elif '/volume/destroy' in url:
			global VOLUME_LIST
			global rbdInstance
			print VOLUME_LIST
			url=self.path
			arg=url.split('?')
			volume_id = int(arg[1].split('=')[1])
			if volume_id in VOLUME_LIST:
				volume_name=str(VOLUME_LIST[int(volume_id)])
				os.system('sudo rbd unmap /dev/rbd/%s/%s'%(POOL_NAME,volume_name))
				rbdInstance.remove(ioctx,volume_name)
				del VOLUME_LIST[int(volume_id)]
				self.wfile.write(json_out({"status":1}))
			else:
				print "here\n"
				self.wfile.write(json_out({"status":0}))
		else:
			self.send_error(404,"File Not Found")
Example #7
0
	def do_GET(self):
		print self.path
		url=self.path
		if '/vm/create' in url:
			whattodo = url
			arguments = []
			arg_split = url.split('?')[1].split('&')
			for i in xrange(0,3):
				arguments.append((arg_split[i].split('='))[1])
			print arguments
			create_vm.create(self,arguments)
		elif '/vm/destroy' in url:
			print url.split('?')[1].split('=')[1]
			DelQueType.destroy(self,url.split('?')[1].split('=')[1])
		elif '/vm/query' in url:
			DelQueType.query(self,url.split('?')[1].split('=')[1])
		elif '/vm/types' in url:
			DelQueType.vmtypes(self)
		elif '/vm/image/list' in url:
			fn=resource_dis.image_id
			l=[]
			for x in fn:
				d={}
				d["id"]=x
				d["name"]=fn[x][2][0]
				l.append(d)
			p={}
			p["iamges"]=l
			self.wfile.write(json_out(p))
		elif '/volume/create' in url:
#global VOLUME_LIST
			url=self.path
			arg=self.path.split('?')
			volume_name = arg[1].split('&')[0].split('=')[1]
			volume_size = arg[1].split('&')[1].split('=')[1]
			actual_size = int(float(volume_size)*(1024**2))
			global rbdInstance
#	try:
			rbdInstance.create(ioctx,str(volume_name),actual_size)
			os.system('sudo rbd map %s --pool %s --name client.admin'%(str(volume_name),str(POOL_NAME)));
			volume_id=resource_dis.voli
			resource_dis.aord[volume_id]=0   #not allocated
			resource_dis.vol_size[volume_id]=volume_size
			resource_dis.VOLUME_LIST[int(resource_dis.voli)]=str(volume_name)
                	resource_dis.voli=resource_dis.voli+1
			print resource_dis.VOLUME_LIST
			self.wfile.write(json_out({"volumeid":volume_id}))
#		except:
#				self.wfile.write(json_out({"volumeid":0}))
				

		elif '/volume/destroy' in url:
#	global VOLUME_LIST
			global rbdInstance
			print resource_dis.VOLUME_LIST
			url=self.path
			arg=url.split('?')
			volume_id = int(arg[1].split('=')[1])
			if volume_id in resource_dis.VOLUME_LIST:
				volume_name=str(resource_dis.VOLUME_LIST[int(volume_id)])
				os.system('sudo rbd unmap /dev/rbd/%s/%s'%(POOL_NAME,volume_name))
				rbdInstance.remove(ioctx,volume_name)
				del resource_dis.VOLUME_LIST[int(volume_id)]
				del resource_dis.aord[int(volume_id)]
				del resource_dis.vol_size[int(volume_id)]
				self.wfile.write(json_out({"status":1}))
			else:
				print "here\n"
				self.wfile.write(json_out({"status":0}))

		elif '/volume/attach' in url:
			url=self.path
			arg=url.split('?')
			args=arg[1]
			a=args.split('&')
			arguments=[a[0].split('=')[1],a[1].split('=')[1]]
			attach_vol.attach(self,arguments)
		elif '/volume/query' in url:
			url=self.path
			arg=url.split('?')
			args=arg[1].split('=')[1]
			DelQueType.vol_query(self,args)
		elif '/volume/detach' in url:
			url=self.path
			arg=url.split('?')
			args=arg[1]
			arguments=args.split('=')[1]
			detach_vol.detach(self,arguments)
		else:
			self.send_error(404,"File Not Found")