Exemple #1
0
func syncPort(data *sjson.Json) (err error) {
	var sapiPorts []*SapiProvisionedPorts
	var fixips []*struct {
		Ips []map[string]string `json:"fixed_ips"`
	}

	port, ok := data.CheckGet("port")
	if !ok {
		return ErrorNoNet
	}
	bytes, err := port.Encode()
	if err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &sapiPorts); err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &fixips); err != nil {
		return err
	}

	new(SapiProvisionedPorts).truncate()
	for index, port := range sapiPorts {
		//fmt.Println(index, *port, fixips[index].Ips[0]["ip_address"], fixips[index].Ips[0]["subnet_id"])
		if len(fixips[index].Ips) >= 1 {
			port.IpAddress = fixips[index].Ips[0]["ip_address"]
			port.SubnetId = fixips[index].Ips[0]["subnet_id"]
		}
		if err := port.insert(); err != nil {
			return err
		}
	}

	return nil
}
Exemple #2
0
func parseResult(data *json.Json) (string, bool) {
	address, ok := data.CheckGet("display_name")
	if ok {
		return address.MustString(), true
	}
	return "", false
}
Exemple #3
0
func syncNet(data *sjson.Json) (err error) {
	var sapiNets []*SapiProvisionedNets

	network, ok := data.CheckGet("network")
	if !ok {
		return ErrorNoNet
	}
	bytes, err := network.Encode()
	if err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &sapiNets); err != nil {
		return err
	}

	new(SapiProvisionedNets).truncate()
	for _, net := range sapiNets {
		if err := net.insert(); err != nil {
			return err
		}
	}
	return nil
}
Exemple #4
0
func syncSubnet(data *sjson.Json) (err error) {
	var sapiSubnets []*SapiProvisionedSubnets

	subnet, ok := data.CheckGet("subnet")
	if !ok {
		return ErrorNoSubnet
	}
	bytes, err := subnet.Encode()
	if err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &sapiSubnets); err != nil {
		return err
	}

	new(SapiProvisionedSubnets).truncate()
	for _, subnet := range sapiSubnets {
		if err := subnet.insert(); err != nil {
			return err
		}
	}
	return nil
}