当前位置: 首页>>代码示例>>Golang>>正文


Golang Chmsg.State方法代码示例

本文整理汇总了Golang中github.com/att/gopkgs/ipc.Chmsg.State方法的典型用法代码示例。如果您正苦于以下问题:Golang Chmsg.State方法的具体用法?Golang Chmsg.State怎么用?Golang Chmsg.State使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/att/gopkgs/ipc.Chmsg的用法示例。


在下文中一共展示了Chmsg.State方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: get_os_defgw

/* Get the default gateway for a project. Returns the string directly to the channel
	that send the osif the message. Expects to be executed as  a go routine.
go get_os_defgw( msg, os_refs, os_projects, id2pname, pname2id )			// do it asynch and return the result on the message channel
*/
func get_os_defgw(msg *ipc.Chmsg, os_refs map[string]*ostack.Ostack, os_projs map[string]*osif_project, id2pname map[string]*string, pname2id map[string]*string) {
	if msg == nil || msg.Response_ch == nil {
		return // prevent accidents
	}

	msg.Response_data = nil

	if msg.Req_data != nil {
		tokens := strings.Split(*(msg.Req_data.(*string)), "/") // split off /junk if it's there
		if tokens[0] == "!" || tokens[0] == "" {                // nothing to work with; bail now
			osif_sheep.Baa(1, "get_defgw: unable to map to a project -- bad token[0] --: %s", *(msg.Req_data.(*string)))
			msg.Response_ch <- msg
			return
		}

		if tokens[0][0:1] == "!" { // first character is a bang, but there is a name/id that follows
			tokens[0] = tokens[0][1:] // ditch the bang and go on
		}

		pid := &tokens[0]
		pname := id2pname[*pid]
		if pname == nil { // it should be an id, but allow for a name/host to be sent in
			osif_sheep.Baa(1, "get_defgw: unable to map to a project -- no pname --: %s", *(msg.Req_data.(*string)))
			pname = &tokens[0]
			pid = pname2id[*pname]
		}

		if pid == nil {
			osif_sheep.Baa(1, "get_defgw: unable to map to a project: %s", *(msg.Req_data.(*string)))
			msg.State = fmt.Errorf("%s could not be mapped to a osif_project", *(msg.Req_data.(*string)))
			msg.Response_ch <- msg
			return
		}

		p := os_projs[*pid] // finally we can find the data associated with the project; maybe
		if p == nil {
			osif_sheep.Baa(1, "get_defgw: unable to map project to data: %s", *pid)
			msg.State = fmt.Errorf("%s could not be mapped to a osif_project", *(msg.Req_data.(*string)))
			msg.Response_ch <- msg
			return
		}

		creds := os_refs[*pname]
		if creds == nil {
			msg.State = fmt.Errorf("defgw: %s could not be mapped to openstack creds ", *pname)
			msg.Response_ch <- msg
			return
		}

		msg.Response_data, _, msg.State = p.Get_default_gw(pid, creds, true)
		msg.Response_ch <- msg
		return
	}

	osif_sheep.Baa(1, "get_defgw:  missing data (nil) in request")
	msg.State = fmt.Errorf("defgw: missing data in request")
	msg.Response_ch <- msg // and send it on its merry way

	return
}
开发者ID:krjoshi,项目名称:tegu,代码行数:64,代码来源:osif_proj.go

示例2: get_all_osvm_info

/*
	Gathers the VM information for all VMs in one or more projects. If "_all_proj" is given as the project name then
	all projects  known to Tegu are fetched.

	Expected to execute as a go routine and writes the resulting array to the channel specified in the message.
*/
func get_all_osvm_info(msg *ipc.Chmsg, os_refs map[string]*ostack.Ostack, os_projs map[string]*osif_project, id2pname map[string]*string, pname2id map[string]*string) {
	if msg == nil || msg.Response_ch == nil {
		return // prevent accidents
	}

	msg.Response_data = nil
	msg.State = nil

	if msg.Req_data == nil {
		osif_sheep.Baa(1, "osvm_info: request data didn't contain a project name or ID")
		msg.State = fmt.Errorf("osvm_info: request data didn't contain a project name or ID")
		msg.Response_ch <- msg
		return
	}

	pid := msg.Req_data.(*string)
	if *pid == "_all_proj" {
		ilist := make([]*Net_vm, 0)
		for k := range os_refs {
			if k != "_ref_" {
				nlist, err := get_projvm_info(&k, os_refs, os_projs, id2pname, pname2id) // dig out next project's stuff
				if err == nil {
					llist := make([]*Net_vm, len(ilist)+len(nlist)) // create array large enough
					copy(llist[:], ilist[:])                        // copy contents into new array
					copy(llist[len(ilist):], nlist[:])
					ilist = llist
				} else {
					osif_sheep.Baa(1, "osvm_info: could not dig out VM information for project: %s: %s", k, err)
				}
			}
		}

		msg.Response_data = ilist
		if len(ilist) <= 0 {
			msg.State = fmt.Errorf("osvm_info: unable to dig any information for all projects")
		} else {
			msg.State = fmt.Errorf("osvm_info: fetched info for all projects: %d elements", len(ilist))
			msg.State = nil
		}
	} else {
		msg.Response_data, msg.State = get_projvm_info(pid, os_refs, os_projs, id2pname, pname2id) // just dig out for the one project
	}

	msg.Response_ch <- msg
}
开发者ID:krjoshi,项目名称:tegu,代码行数:51,代码来源:osif_proj.go

示例3: get_os_hostinfo

/*
	Get openstack host information.
	Given a project-id/host as input, dig out all of the host's information and build a struct
	that can be passed into the network manager as an add host to graph request. This
	expects to run as a go routine and to write the response directly back on the channel
	givn in the message block.
*/
func get_os_hostinfo(msg *ipc.Chmsg, os_refs map[string]*ostack.Ostack, os_projs map[string]*osif_project, id2pname map[string]*string, pname2id map[string]*string) {
	if msg == nil || msg.Response_ch == nil {
		return // prevent accidents
	}

	msg.Response_data = nil

	tokens := strings.Split(*(msg.Req_data.(*string)), "/") // break project/host into bits
	if len(tokens) != 2 || tokens[0] == "" || tokens[1] == "" {
		osif_sheep.Baa(1, "get hostinfo: unable to map to a project: %s bad tokens", *(msg.Req_data.(*string)))
		msg.State = fmt.Errorf("invalid project/hostname string: %s", *(msg.Req_data.(*string)))
		msg.Response_ch <- msg
		return
	}

	if tokens[0] == "!" { // !//ipaddress was given; we've got nothing, so bail now
		osif_sheep.Baa(1, "get hostinfo: unable to map to a project: %s lone bang", *(msg.Req_data.(*string)))
		msg.Response_ch <- msg
		return
	}

	if tokens[0][0:1] == "!" { // first character is a bang, but there is a name/id that follows
		tokens[0] = tokens[0][1:] // ditch it for this
	}

	pid := &tokens[0]
	pname := id2pname[*pid]
	if pname == nil { // it should be an id, but allow for a name/host to be sent in
		pname = &tokens[0]
		pid = pname2id[*pname]
	}

	if pid == nil {
		osif_sheep.Baa(1, "get hostinfo: unable to map to an project (nil pid): %s", *(msg.Req_data.(*string))) // might be !project/vm, and so this is ok
		msg.State = fmt.Errorf("%s could not be mapped to an osif_project", *(msg.Req_data.(*string)))
		msg.Response_ch <- msg
		return
	}

	p := os_projs[*pid]
	if p == nil {
		osif_sheep.Baa(1, "get hostinfo: %s mapped to a pid; pid did not map to project: %s", *(msg.Req_data.(*string)), *pid)
		msg.State = fmt.Errorf("%s could not be mapped to an osif_project", *(msg.Req_data.(*string)))
		msg.Response_ch <- msg
		return
	}

	creds := os_refs[*pname]
	if creds == nil {
		osif_sheep.Baa(1, "get hostinfo: %s mapped to a project; did not map to creds: %s", *(msg.Req_data.(*string)), *pname)
		msg.State = fmt.Errorf("%s could not be mapped to openstack creds ", *pname)
		msg.Response_ch <- msg
		return
	}

	osif_sheep.Baa(2, "lazy update: get host info setup complete for (%s) %s", *pname, *(msg.Req_data.(*string)))

	search := *pid + "/" + tokens[1] // search string must be id/hostname
	name, id, ip4, fip4, mac, gw, phost, gwmap, _, err := p.Get_info(&search, creds, true)
	if err != nil {
		msg.State = fmt.Errorf("unable to retrieve host info: %s", err)
		msg.Response_ch <- msg
		return
	}

	osif_sheep.Baa(2, "lazyupdate: Response_data = %s %s %s %s %s %s", safe(name), safe(id), safe(ip4), safe(phost), safe(mac), safe(gw))
	msg.Response_data = Mk_netreq_vm(name, id, ip4, nil, phost, mac, gw, fip4, gwmap) // build the vm data block for network manager
	msg.Response_ch <- msg                                                            // and send it on its merry way

	return
}
开发者ID:krjoshi,项目名称:tegu,代码行数:78,代码来源:osif_proj.go

示例4: Res_manager


//.........这里部分代码省略.........
			rr_rate = clike.Atoi( *p )
			if rr_rate < 900 {
				if rr_rate < 120 {
					rm_sheep.Baa( 0, "NOTICE: reservation refresh rate in config is insanely low (%ds) and was changed to 1800s", rr_rate )
					rr_rate = 1800
				} else {
					rm_sheep.Baa( 0, "NOTICE: reservation refresh rate in config is too low: %ds", rr_rate )
				}
			}
		}
	}

	send_meta_counter := 200;										// send meta f-mods only now and again
	rm_sheep.Baa( 1, "ovs table number %d used for metadata marking", alt_table )

	res_refresh = time.Now().Unix() + int64( rr_rate )				// set first refresh in an hour (ignored if hto_limit not set
	inv = Mk_inventory( )
	inv.chkpt = chkpt.Mk_chkpt( ckptd, 10, 90 )

	last_qcheck = time.Now().Unix()

	tkl_ch := make( chan *ipc.Chmsg, 5 )								// special, short buffer, channel for tickles allows 5 to queue before blocking sender
	tklr.Add_spot( 2, tkl_ch, REQ_PUSH, nil, ipc.FOREVER )				// push reservations to agent just before they go live
	tklr.Add_spot( 1, tkl_ch, REQ_SETQUEUES, nil, ipc.FOREVER )			// drives us to see if queues need to be adjusted
	tklr.Add_spot( 5, tkl_ch, REQ_RTRY_CHKPT, nil, ipc.FOREVER )		// ensures that we retried any missed checkpoints
	tklr.Add_spot( 60, tkl_ch, REQ_VET_RETRY, nil, ipc.FOREVER )		// run the retry queue if it has size

	go rm_lookup( rmgrlu_ch, inv )

	rm_sheep.Baa( 3, "res_mgr is running  %x", my_chan )
	for {
		select {									// select next ready message on either channel
			case msg = <- tkl_ch:					// msg available on tickle channel
				msg.State = nil						// nil state is OK, no error
				my_chan <- msg;						// just pass it through; tkl_ch has a small buffer (blocks quickly) and this prevents filling the main queue w/ tickles if we get busy	

			case msg = <- my_chan:					// process message from the main channel
				rm_sheep.Baa( 3, "processing message: %d", msg.Msg_type )
				switch msg.Msg_type {
					case REQ_NOOP:			// just ignore

					case REQ_ADD:
						msg.State = inv.Add_res( msg.Req_data )			// add will determine the pledge type and do the right thing
						msg.Response_data = nil


					case REQ_ALLUP:			// signals that all initialisation is complete (chkpting etc. can go)
						all_sys_up = true
						// periodic checkpointing turned off with the introduction of tegu_ha
						//tklr.Add_spot( 180, my_chan, REQ_CHKPT, nil, ipc.FOREVER )		// tickle spot to drive us every 180 seconds to checkpoint

					case REQ_RTRY_CHKPT:									// called to attempt to send a queued checkpoint request
						if all_sys_up {
							if retry_chkpt {
								rm_sheep.Baa( 3, "invoking checkpoint (retry)" )
								retry_chkpt, last_chkpt = inv.write_chkpt( last_chkpt )
							}
						}

					case REQ_CHKPT:											// external thread has requested checkpoint
						if all_sys_up {
							rm_sheep.Baa( 3, "invoking checkpoint" )
							retry_chkpt, last_chkpt = inv.write_chkpt( last_chkpt )
						}

					case REQ_DEL:											// user initiated delete -- requires cookie
开发者ID:att,项目名称:tegu,代码行数:67,代码来源:res_mgr.go

示例5: Osif_mgr


//.........这里部分代码省略.........
				if cfg_data[os_sects[i]] != nil { // section name supplied, override defaults with information from the section
					if cfg_data[os_sects[i]]["url"] != nil {
						url = cfg_data[os_sects[i]]["url"]
					}
					if cfg_data[os_sects[i]]["usr"] != nil {
						usr = cfg_data[os_sects[i]]["usr"]
					}
					if cfg_data[os_sects[i]]["passwd"] != nil {
						passwd = cfg_data[os_sects[i]]["passwd"]
					}
					if cfg_data[os_sects[i]]["project"] != nil {
						project = cfg_data[os_sects[i]]["project"]
					}
				}
				os_refs[*project] = ostack.Mk_ostack(url, usr, passwd, project)
				os_refs["_ref_"] = os_refs[*project] // a quick access reference when any one will do
			}
		}

		os_projects = make(map[string]*osif_project)
		add2projects(os_projects, os_refs, pname2id, 0) // add refernces to the projects list
	}

	// ---------------- end config parsing ----------------------------------------

	if os_admin != nil { // only if we are using openstack as a database
		//tklr.Add_spot( 3, my_chan, REQ_GENCREDS, nil, 1 )						// add tickle spot to drive us once in 3s and then another to drive us based on config refresh rate
		tklr.Add_spot(int64(180), my_chan, REQ_GENCREDS, nil, ipc.FOREVER)
	}

	osif_sheep.Baa(2, "osif manager is running  %x", my_chan)
	for {
		msg = <-my_chan // wait for next message from tickler
		msg.State = nil // default to all OK

		osif_sheep.Baa(3, "processing request: %d", msg.Msg_type)
		switch msg.Msg_type {
		case REQ_GENMAPS: // driven by tickler
			// deprecated with switch to lazy update

		case REQ_GENCREDS: // driven by tickler now and then
			if os_admin != nil {
				os_refs, pname2id, id2pname = update_project(os_admin, os_refs, os_projects, pname2id, id2pname, os_list == "all")
			}

			/* ---- before lite ----
			case REQ_VM2IP:														// driven by tickler; gen a new vm translation map and push to net mgr
				m := mapvm2ip( os_refs )
				if m != nil {
					count := 0;
					msg := ipc.Mk_chmsg( )
					msg.Send_req( nw_ch, nil, REQ_VM2IP, m, nil )					// send new map to network as it is managed there
					osif_sheep.Baa( 2, "VM2IP mapping updated from openstack" )
					for k, v := range m {
						osif_sheep.Baa( 3, "VM mapped: %s ==> %s", k, *v )
						count++;
					}
					osif_sheep.Baa( 2, "mapped %d VM names/IDs from openstack (verbose 3 for debug list)", count )
				}
			*/

		case REQ_IP2MACMAP: // generate an ip to mac map and send to those who need it (fq_mgr at this point)
			freq := ipc.Mk_chmsg() // need a new request to pass to fq_mgr
			data, err := get_ip2mac(os_projects)
			if err == nil {
				osif_sheep.Baa(2, "sending ip2mac map to fq_mgr")
开发者ID:krjoshi,项目名称:tegu,代码行数:67,代码来源:osif.go

示例6: Fq_mgr


//.........这里部分代码省略.........
		}

		if p := cfg_data["fqmgr"]["verbose"]; p != nil {
			fq_sheep.Set_level(uint(clike.Atoi(*p)))
		}

		if p := cfg_data["fqmgr"]["phost_suffix"]; p != nil { // suffix added to physical host strings for agent commands
			if *p != "" {
				phost_suffix = p
				fq_sheep.Baa(1, "physical host names will be suffixed with: %s", *phost_suffix)
			}
		}
	}
	// ----- end config file munging ---------------------------------------------------

	//tklr.Add_spot( qcheck_freq, my_chan, REQ_SETQUEUES, nil, ipc.FOREVER );  	// tickle us every few seconds to adjust the ovs queues if needed

	if switch_hosts == nil {
		tklr.Add_spot(2, my_chan, REQ_CHOSTLIST, nil, 1)                     // tickle once, very soon after starting, to get a host list
		tklr.Add_spot(hcheck_freq, my_chan, REQ_CHOSTLIST, nil, ipc.FOREVER) // tickles us every once in a while to update host list
		fq_sheep.Baa(2, "host list will be requested from openstack every %ds", hcheck_freq)
	} else {
		host_list = switch_hosts
		fq_sheep.Baa(0, "static host list from config used for setting OVS queues: %s", *host_list)
	}

	if sdn_host != nil && *sdn_host != "" {
		uri_prefix = fmt.Sprintf("http://%s", *sdn_host)
	}

	fq_sheep.Baa(1, "flowmod-queue manager is running, sdn host: %s", *sdn_host)
	for {
		msg = <-my_chan // wait for next message
		msg.State = nil // default to all OK

		fq_sheep.Baa(3, "processing message: %d", msg.Msg_type)
		switch msg.Msg_type {
		case REQ_GEN_FMOD: // generic fmod; just pass it along w/o any special handling
			if msg.Req_data != nil {
				fdata = msg.Req_data.(*Fq_req) // pointer at struct with all of our expected goodies
				send_gfmod_agent(fdata, ip2mac, host_list, phost_suffix)
			}

		case REQ_BWOW_RESERVE: // oneway bandwidth flow-mod generation
			msg.Response_ch = nil          // nothing goes back from this
			fdata = msg.Req_data.(*Fq_req) // pointer at struct with all of the expected goodies
			send_bwow_fmods(fdata, ip2mac, phost_suffix)

		case REQ_BW_RESERVE: // bandwidth endpoint flow-mod creation; single agent script creates all needed fmods
			fdata = msg.Req_data.(*Fq_req) // pointer at struct with all of the expected goodies
			send_bw_fmods(fdata, ip2mac, phost_suffix)
			msg.Response_ch = nil // nothing goes back from this

		case REQ_IE_RESERVE: // proactive ingress/egress reservation flowmod  (this is likely deprecated as of 3/21/2015 -- resmgr invokes the bw_fmods script via agent)
			fdata = msg.Req_data.(*Fq_req) // user view of what the flow-mod should be

			if uri_prefix != "" { // an sdn controller -- skoogi -- is enabled
				msg.State = gizmos.SK_ie_flowmod(&uri_prefix, *fdata.Match.Ip1, *fdata.Match.Ip2, fdata.Expiry, fdata.Espq.Queuenum, fdata.Espq.Switch, fdata.Espq.Port)

				if msg.State == nil { // no error, no response to requestor
					fq_sheep.Baa(2, "proactive reserve successfully sent: uri=%s h1=%s h2=%s exp=%d qnum=%d swid=%s port=%d dscp=%d",
						uri_prefix, fdata.Match.Ip1, fdata.Match.Ip2, fdata.Expiry, fdata.Espq.Queuenum, fdata.Espq.Switch, fdata.Espq.Port)
					msg.Response_ch = nil
				} else {
					// do we need to suss out the id and mark it failed, or set a timer on it,  so as not to flood reqmgr with errors?
					fq_sheep.Baa(1, "ERR: proactive reserve failed: uri=%s h1=%s h2=%s exp=%d qnum=%d swid=%s port=%d  [TGUFQM008]",
开发者ID:robert-eby,项目名称:tegu,代码行数:67,代码来源:fq_mgr.go


注:本文中的github.com/att/gopkgs/ipc.Chmsg.State方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。