Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example usage: Set DHCP options #143

Open
gavmckee80 opened this issue Jul 23, 2021 · 1 comment
Open

Example usage: Set DHCP options #143

gavmckee80 opened this issue Jul 23, 2021 · 1 comment
Assignees

Comments

@gavmckee80
Copy link

Would it be possible for you to provide an example of the following

Using the API to create a network , set the specific DHCP options of that network (router, DNS servers, domain etc) set the member servers for that DHCP scope and define a range within the scope . How do I gracefully handle a network that already exists , the Python low level API has an update_if_exists flag which is useful

network = objects.Network.create(conn, network_view='default', cidr=cidr,update_if_exists=True,options=options,members=dhcp_members)
package main

import (
	"fmt"

	ibclient "github.com/infobloxopen/infoblox-go-client"
)

func main() {
	hostConfig := ibclient.HostConfig{
		Host:     "XXXXXXXX",
		Version:  "2.2",
		Port:     "443",
		Username: "XXXXXX",
		Password: "XXXXXXX",
	}
	transportConfig := ibclient.NewTransportConfig("false", 20, 10)
	requestBuilder := &ibclient.WapiRequestBuilder{}
	requestor := &ibclient.WapiHttpRequestor{}
	conn, err := ibclient.NewConnector(hostConfig, transportConfig, requestBuilder, requestor)
	if err != nil {
		fmt.Println(err)
	}
	defer conn.Logout()

	// No idea what the cmp type or what my tenant id id , so need to work on that
	objMgr := ibclient.NewObjectManager(conn, "", "")

	//Fetches grid information
	fmt.Println(objMgr.GetFixedAddressByRef("fixedaddress/ZG5zLmZpeGVkX2FkZHJlc3MkMTAuMy4yNi4xMDEuMC4u:10.3.26.101/default"))

	net, err := objMgr.CreateNetwork("default", "10.200.0.0/16", false, "Azure prefix (testing)", nil)
	
	if err != nil {
		fmt.Println(err)
	}
	fmt.Print(net)
	fmt.Print(net.ReturnFields())
@anagha-infoblox
Copy link
Contributor

Hi @gavmckee80,

As of now, we do not support update_if_exists flag during creation for any of the objects in Go-client. We will consider this as a feature enhancement and try to implement the same before our next release. Workaround for the same would be to Get an object and check if the returned value is nil. If the returned object is nil, then the code would proceed with creation else an update function can be called.
For example, to handle the creation or updation of a network 10.200.0.0/16,

package main
import (
        "fmt"
        ibclient "github.com/infobloxopen/infoblox-go-client"
)

func main() {
        hostConfig := ibclient.HostConfig{
		Host:     "XXXXXXXX",
		Version:  "2.2",
		Port:     "443",
		Username: "XXXXXX",
		Password: "XXXXXXX",
        }
        transportConfig := ibclient.NewTransportConfig("false", 20, 10)
        requestBuilder := &ibclient.WapiRequestBuilder{}
        requestor := &ibclient.WapiHttpRequestor{}
        conn, err := ibclient.NewConnector(hostConfig, transportConfig, requestBuilder, requestor)
        if err != nil {
                fmt.Println(err)
        }
        defer conn.Logout()

        objMgr := ibclient.NewObjectManager(conn, "", "")
        
        setEas := ibclient.EA{"Location" : "Test loc.", "Site" : "Test site"}
        getNet, err := objMgr.GetNetwork("netViewName", "10.200.0.0/16", false, nil)
        if getNet != nil {
                updateNet, err := objMgr.UpdateNetwork(getNet.Ref, setEas, "updated comment")
                if err != nil {
                        fmt.Println(err)
                }
                fmt.Println(updateNet)
        } else {
                createNet, err := objMgr.CreateNetwork("netViewName", "10.200.0.0/16", false, "comment", setEas)
                if err != nil{
                        fmt.Println(err)
                }
                fmt.Println(createNet)
        }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants