-
Manuel Kieweg authored
Merge branch '60-create-interfaces-for-internal-data-structure' into 64-openconfig-transport-to-core
Manuel Kieweg authoredMerge branch '60-create-interfaces-for-internal-data-structure' into 64-openconfig-transport-to-core
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
client.go 3.51 KiB
package ciena
import (
"bytes"
"code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"code.fbi.h-da.de/cocsn/gosdn/sbi/restconf/util"
apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client"
"crypto/tls"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
log "github.com/sirupsen/logrus"
"net/http"
)
//MCPClient handles requests to a Ciena MCP RESTCONF endpoint
type MCPClient struct {
transport *httptransport.Runtime
client *apiclient.ServiceTopologyTAPI
database *database.Database
buffer *bytes.Buffer
config *interfaces.ClientConfig
}
// GetConfig returns a ClientConfig struct containing
// the current configuration stat of the Ciena SBI client
func (c MCPClient) GetConfig() interfaces.ClientConfig {
return *c.config
}
// ListPorts is a stub to satisfy the interface
// TODO: Implement
func (c MCPClient) ListPorts() map[int]interfaces.Port {
return nil
}
// PushReceiver is a stub to satisfy the interface
// TODO: Implement
func (c MCPClient) PushReceiver() error {
return nil
}
//NewMCPClient creates a Ciena flavores TAPI client
func NewMCPClient(endpoint, username, password string, database *database.Database, config *interfaces.ClientConfig) *MCPClient {
// create the transport
transport := httptransport.New(endpoint, "/", nil)
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
// create the API client, with the transport
basicAuth := httptransport.BasicAuth(username, password)
// authenticate client
transport.DefaultAuthentication = basicAuth
client := apiclient.New(transport, strfmt.Default)
buffer := new(bytes.Buffer)
transport.Consumers[runtime.JSONMime] = util.YANGConsumer{Data: buffer}
return &MCPClient{
transport: transport,
client: client,
database: database,
buffer: buffer,
config: config,
}
}
// GetConnections implements the TAPI Connectivity GetConnections call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
func (c *MCPClient) GetConnections() error {
defer c.buffer.Reset()
_, err := c.client.TapiConnectivityCore.GetTapiCoreContextConnection(nil)
c.database.StoreConnections(c.buffer.String())
log.Debug(c.buffer.Next(25))
return err
}
// GetLinks implements the TAPI Topology GetLinks call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
func (c *MCPClient) GetLinks() error {
defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil)
c.database.StoreLinks(c.buffer.String())
log.Debug(c.buffer.Next(25))
return err
}
// GetNodes implements the TAPI Topology GetNodes call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
func (c *MCPClient) GetNodes() error {
defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil)
c.database.StoreNodes(c.buffer.String())
log.Debug(c.buffer.Next(25))
return err
}
// GetNodeEdgePoints implements the TAPI Topology GetNodeEdgePoints call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
func (c *MCPClient) GetNodeEdgePoints() error {
defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNodeEdgePoint(nil)
c.database.StoreNodeEdgePoints(c.buffer.String())
log.Debug(c.buffer.Next(25))
return err
}