Skip to content

Commit

Permalink
Merge branch 'vyos:current' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
marekm72 authored Nov 21, 2024
2 parents 2dd90f1 + 16d743a commit 67dd6f0
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/automation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VyOS Automation

.. toctree::
:maxdepth: 2

vyos-api
vyos-ansible
terraform/index
Expand All @@ -14,4 +14,4 @@ VyOS Automation
command-scripting
cloud-init
vyos-pyvyos

vyos-govyos
203 changes: 203 additions & 0 deletions docs/automation/vyos-govyos.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
:lastproofread: 2024-03-10

.. _vyos-govyos:

go-vyos
=======

go-vyos is a Go library designed for interacting with VyOS devices through
their REST API. This documentation is intended to guide you in using go-vyos for
programmatic management of your VyOS devices.

- `go-vyos Documentation & Source Code on GitHub <https://github.com/ganawaj/go-vyos>`_
allows you to access and contribute to the library's code.
- `go-vyos on pkg.go.dev <https://pkg.go.dev/github.com/ganawaj/[email protected]/vyos>`_ for detailed instructions
on the installation, configuration, and operation of the go-vyos library.


Installation
------------

You can install go-vyos:

.. code-block:: bash
go install "github.com/ganawaj/go-vyos/vyos"
Getting Started
---------------

Importing and Disabling TLS Verification
-------------------------------------------------

.. code-block:: none
import "github.com/ganawaj/go-vyos/vyos"
client := vyos.NewClient(nil).WithToken("AUTH_KEY").WithURL("https://192.168.0.1").Insecure()
Initializing a VyDevice Object
------------------------------

.. code-block:: none
import (
"github.com/ganawaj/go-vyos/vyos"
"os"
)
hostname := os.Getenv('VYDEVICE_HOSTNAME')
port := os.Getenv('VYDEVICE_PORT')
url := fmt.Sprintf("https://%s:%s", hostname, port)
apikey := os.Getenv('VYDEVICE_APIKEY')
verify_ssl := os.Getenv('VYDEVICE_VERIFY_SSL')
client := vyos.NewClient(nil).WithToken(apikey).WithURL(url)
if verify_ssl == "false" {
client = client.Insecure()
}
Using go-vyos
----------------

Configure, then Set
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Conf.Set(ctx, "interfaces ethernet eth0 address 192.168.1.1/24")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
Show a Single Object Value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Show.Do(ctx, "interfaces dummy dum1 address")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
fmt.Printf("Data: %v\n", out.Data)
Configure, then Show Object
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Conf.Get(ctx, "interfaces dummy dum1", nil)
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
fmt.Printf("Data: %v\n", out.Data)
Configure, then Show Multivalue Object
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
options := RetrieveOptions{
Multivalue: true,
}
out, resp, err := c.Conf.Get(ctx, "interfaces dummy dum1", options)
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
Configure, then Delete Object
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Conf.Delete(ctx, "interfaces dummy dum1")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
Configure, then Save
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Conf.Save(ctx, "")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
Configure, then Save File
-------------------------

.. code-block:: none
out, resp, err := c.Conf.Save(ctx, "/config/test300.config")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
Show Object
^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Show.Do(ctx, "system image")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
fmt.Printf("Data: %v\n", out.Data)
Generate Object
^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Generate.Do(ctx, "pki wireguard key-pair")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
fmt.Printf("Data: %v\n", out.Data)
Reset Object
^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.Reset.Do(ctx, "ip bgp 192.0.2.11")
if err != nil {
panic("Error: %v", err)
}
fmt.Println(out.Success)
fmt.Printf("Data: %v\n", out.Data)
Configure, then Load File
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: none
out, resp, err := c.ConfigFile.Load(ctx, "/config/test300.config")
.. _go-vyos: https://github.com/ganawaj/go-vyos
9 changes: 9 additions & 0 deletions docs/configuration/container/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ Container Networks
Define IPv4 and/or IPv6 prefix for a given network name.
Both IPv4 and IPv6 can be used in parallel.

.. cfgcmd:: set container network <name> mtu <number>

Configure :abbr:`MTU (Maximum Transmission Unit)` for a given network. It
is the size (in bytes) of the largest ethernet frame sent on this link.

.. cfgcmd:: set container network <name> no-name-server

Disable Domain Name System (DNS) plugin for this network.

.. cfgcmd:: set container network <name> vrf <nme>

Bind container network to a given VRF instance.
Expand Down

0 comments on commit 67dd6f0

Please sign in to comment.