本文整理匯總了Golang中github.com/Juniper/contrail-go-api/types.VirtualMachineInterface.GetVirtualMachineInterfaceMacAddresses方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirtualMachineInterface.GetVirtualMachineInterfaceMacAddresses方法的具體用法?Golang VirtualMachineInterface.GetVirtualMachineInterfaceMacAddresses怎麽用?Golang VirtualMachineInterface.GetVirtualMachineInterfaceMacAddresses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Juniper/contrail-go-api/types.VirtualMachineInterface
的用法示例。
在下文中一共展示了VirtualMachineInterface.GetVirtualMachineInterfaceMacAddresses方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateInstanceMetadata
func (c *Controller) updateInstanceMetadata(
pod *api.Pod, nic *types.VirtualMachineInterface, address, gateway string) {
doUpdate := false
if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
doUpdate = true
}
var newValue, oldValue InstanceMetadata
if data, ok := pod.Annotations[MetadataAnnotationTag]; ok {
json.Unmarshal([]byte(data), &oldValue)
}
newValue.Uuid = nic.GetUuid()
var mac_address string
addressArr := nic.GetVirtualMachineInterfaceMacAddresses()
if len(addressArr.MacAddress) > 0 {
mac_address = addressArr.MacAddress[0]
} else {
glog.Errorf("interface %s: no mac-addresses", nic.GetName())
}
newValue.MacAddress = mac_address
newValue.IpAddress = address
newValue.Gateway = gateway
if !doUpdate && reflect.DeepEqual(newValue, oldValue) {
return
}
encoded, err := json.Marshal(&newValue)
if err != nil {
glog.Errorf("JSON encode: %v", err)
return
}
pod.Annotations[MetadataAnnotationTag] = string(encoded)
_, err = c.kube.Pods(pod.Namespace).Update(pod)
if err != nil {
// Update will return an error if the pod object that we are
// working with is stale.
glog.Infof("Pod Update %s: %v", pod.Name, err)
}
}
示例2: updateInstanceMetadata
func (c *Controller) updateInstanceMetadata(
pod *api.Pod, nic *types.VirtualMachineInterface, address, gateway string) {
doUpdate := false
if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
doUpdate = true
}
if updateElement(pod.Annotations, "nic_uuid", nic.GetUuid()) {
doUpdate = true
}
var mac_address string
addressArr := nic.GetVirtualMachineInterfaceMacAddresses()
if len(addressArr.MacAddress) > 0 {
mac_address = addressArr.MacAddress[0]
} else {
glog.Errorf("interface %s: no mac-addresses", nic.GetName())
}
if updateElement(pod.Annotations, "mac_address", mac_address) {
doUpdate = true
}
if updateElement(pod.Annotations, "ip_address", address) {
doUpdate = true
}
if updateElement(pod.Annotations, "gateway", gateway) {
doUpdate = true
}
if !doUpdate {
return
}
_, err := c.kube.Pods(pod.Namespace).Update(pod)
if err != nil {
// Update will return an error if the pod object that we are
// working with is stale.
glog.Infof("Pod Update %s: %v", pod.Name, err)
}
}