diff --git a/cli/pkg/serviceLib/flags/flags.go b/cli/pkg/serviceLib/flags/flags.go index de259d3..852bf9a 100644 --- a/cli/pkg/serviceLib/flags/flags.go +++ b/cli/pkg/serviceLib/flags/flags.go @@ -2,6 +2,12 @@ package flags +// Constants +const ( + PROTOCOL_HTTP = "http" + PROTOCOL_HTTPS = "https" +) + // CLI flag component descriptor const ( SERVICE string = "serv" @@ -40,9 +46,9 @@ const ( SERVICE_NET_PORT string = SERVICE + "-" + NET_PORT SERVICE_NET_PORT_SH string = "p" SERVICE_INSECURE string = SERVICE + "-" + INSECURE - SERVICE_INSECURE_SH string = "" //"s" + SERVICE_INSECURE_SH string = "s" SERVICE_PROTOCOL string = SERVICE + "-" + PROTOCOL - SERVICE_PROTOCOL_SH string = "" //"t" + SERVICE_PROTOCOL_SH string = "t" APPLIANCE_ID string = APPLIANCE + "-" + ID APPLIANCE_ID_SH string = "L" @@ -92,26 +98,26 @@ const ( SERVICE_NET_IP_DFLT string = "127.0.0.1" SERVICE_NET_PORT_DFLT uint16 = 8080 SERVICE_INSECURE_DFLT bool = false - SERVICE_PROTOCOL_DFLT string = "http" + SERVICE_PROTOCOL_DFLT string = PROTOCOL_HTTPS APPLIANCE_NET_IP_DFLT string = "127.0.0.1" APPLIANCE_NET_PORT_DFLT uint16 = 443 APPLIANCE_INSECURE_DFLT bool = false - APPLIANCE_PROTOCOL_DFLT string = "https" + APPLIANCE_PROTOCOL_DFLT string = PROTOCOL_HTTPS APPLIANCE_USERNAME_DFLT string = "dummyuser" APPLIANCE_PASSWORD_DFLT string = "dummypswd" BLADE_NET_IP_DFLT string = "127.0.0.1" BLADE_NET_PORT_DFLT uint16 = 443 BLADE_INSECURE_DFLT bool = false - BLADE_PROTOCOL_DFLT string = "https" + BLADE_PROTOCOL_DFLT string = PROTOCOL_HTTPS BLADE_USERNAME_DFLT string = "root" BLADE_PASSWORD_DFLT string = "0penBmc" HOST_NET_IP_DFLT string = "127.0.0.1" HOST_NET_PORT_DFLT uint16 = 8082 HOST_INSECURE_DFLT bool = false - HOST_PROTOCOL_DFLT string = "http" + HOST_PROTOCOL_DFLT string = PROTOCOL_HTTP HOST_USERNAME_DFLT string = "admin" HOST_PASSWORD_DFLT string = "admin12345" diff --git a/cli/pkg/serviceLib/serviceRequests/appliances.go b/cli/pkg/serviceLib/serviceRequests/appliances.go index 5adacb4..51b1c54 100644 --- a/cli/pkg/serviceLib/serviceRequests/appliances.go +++ b/cli/pkg/serviceLib/serviceRequests/appliances.go @@ -39,7 +39,7 @@ func (r *ServiceRequestAddAppliance) Execute() (*service.Appliance, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "AppliancesCred", fmt.Sprintf("%+v", *r.ApplianceCred)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceTcp", fmt.Sprintf("%+v", *r.ApplianceTcp)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) insecure := r.ApplianceTcp.GetInsecure() protocol := r.ApplianceTcp.GetProtocol() @@ -79,7 +79,7 @@ func (r *ServiceRequestDeleteAppliance) Execute() (*service.Appliance, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) deletedAppliance, err := serviceWrap.DeleteApplianceById(serviceClient, r.ApplianceId.GetId()) if err != nil { @@ -102,7 +102,7 @@ func NewServiceRequestListAppliances(cmd *cobra.Command) *ServiceRequestListAppl func (r *ServiceRequestListAppliances) Execute() (*[]*service.Appliance, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) appliances, err := serviceWrap.GetAllAppliances(serviceClient) if err != nil { @@ -147,7 +147,7 @@ func (r *ServiceRequestRenameAppliance) Execute() (*service.Appliance, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "NewApplianceId", fmt.Sprintf("%+v", *r.NewApplianceId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) appliance, err := serviceWrap.RenameApplianceById(serviceClient, r.ApplianceId.GetId(), r.NewApplianceId.GetId()) if err != nil { @@ -173,7 +173,7 @@ func (r *ServiceRequestResyncAppliance) Execute() (*service.Appliance, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) appliance, err := serviceWrap.ResyncApplianceById(serviceClient, r.ApplianceId.GetId()) if err != nil { diff --git a/cli/pkg/serviceLib/serviceRequests/blades.go b/cli/pkg/serviceLib/serviceRequests/blades.go index 5b0911e..d80bced 100644 --- a/cli/pkg/serviceLib/serviceRequests/blades.go +++ b/cli/pkg/serviceLib/serviceRequests/blades.go @@ -39,7 +39,7 @@ func (r *ServiceRequestAddBlade) Execute() (*service.Blade, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeCred", fmt.Sprintf("%+v", *r.BladeCred)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeTcp", fmt.Sprintf("%+v", *r.BladeTcp)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) insecure := r.BladeTcp.GetInsecure() protocol := r.BladeTcp.GetProtocol() @@ -82,7 +82,7 @@ func (r *ServiceRequestDeleteBlade) Execute() (*service.Blade, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) blade, err := serviceWrap.DeleteBladeById(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId()) if err != nil { @@ -123,7 +123,7 @@ func (r *ServiceRequestListBlades) Execute() (*serviceWrap.ApplianceBladeSummary klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if !r.AllAppliances() && !r.AllBlades() { blade, err := serviceWrap.FindBladeById_SingleAppl(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId()) @@ -201,7 +201,7 @@ func (r *ServiceRequestRenameBlade) Execute() (*service.Blade, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "NewBladeId", fmt.Sprintf("%+v", *r.NewBladeId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) blade, err := serviceWrap.RenameBladeById(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId(), r.NewBladeId.GetId()) if err != nil { @@ -230,7 +230,7 @@ func (r *ServiceRequestResyncBlade) Execute() (*service.Blade, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) blade, err := serviceWrap.ResyncBladeById(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId()) if err != nil { diff --git a/cli/pkg/serviceLib/serviceRequests/hosts.go b/cli/pkg/serviceLib/serviceRequests/hosts.go index 2634bda..1bb1701 100644 --- a/cli/pkg/serviceLib/serviceRequests/hosts.go +++ b/cli/pkg/serviceLib/serviceRequests/hosts.go @@ -36,7 +36,7 @@ func (r *ServiceRequestAddHost) Execute() (*service.Host, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostCred", fmt.Sprintf("%+v", *r.HostCred)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostTcp", fmt.Sprintf("%+v", *r.HostTcp)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) insecure := r.HostTcp.GetInsecure() protocol := r.HostTcp.GetProtocol() @@ -79,7 +79,7 @@ func (r *ServiceRequestDeleteHost) Execute() (*service.Host, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostId", fmt.Sprintf("%+v", *r.HostId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) host, err = serviceWrap.DeleteHostById(serviceClient, r.HostId.GetId()) if err != nil { @@ -102,7 +102,7 @@ func NewServiceRequestListHosts(cmd *cobra.Command) *ServiceRequestListHosts { func (r *ServiceRequestListHosts) Execute() (*[]*service.Host, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) hosts, err := serviceWrap.GetAllHosts(serviceClient) if err != nil { @@ -147,7 +147,7 @@ func (r *ServiceRequestRenameHost) Execute() (*service.Host, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostId", fmt.Sprintf("%+v", *r.HostId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "NewHostId", fmt.Sprintf("%+v", *r.NewHostId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) host, err := serviceWrap.RenameHostById(serviceClient, r.HostId.GetId(), r.NewHostId.GetId()) if err != nil { @@ -173,7 +173,7 @@ func (r *ServiceRequestResyncHost) Execute() (*service.Host, error) { klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostId", fmt.Sprintf("%+v", *r.HostId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) host, err := serviceWrap.ResyncHostById(serviceClient, r.HostId.GetId()) if err != nil { diff --git a/cli/pkg/serviceLib/serviceRequests/memory-devices.go b/cli/pkg/serviceLib/serviceRequests/memory-devices.go index cf23fae..07c204e 100644 --- a/cli/pkg/serviceLib/serviceRequests/memory-devices.go +++ b/cli/pkg/serviceLib/serviceRequests/memory-devices.go @@ -45,7 +45,7 @@ func (r *ServiceRequestListHostMemoryDevices) Execute() (*serviceWrap.HostMemory klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostId", fmt.Sprintf("%+v", *r.HostId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "MemoryDeviceId", fmt.Sprintf("%+v", *r.MemoryDeviceId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if r.AllHosts() && r.AllMemoryDevices() { summary, err = serviceWrap.GetMemoryDevices_AllHosts(serviceClient) diff --git a/cli/pkg/serviceLib/serviceRequests/memory.go b/cli/pkg/serviceLib/serviceRequests/memory.go index 747c5a8..a7b391e 100644 --- a/cli/pkg/serviceLib/serviceRequests/memory.go +++ b/cli/pkg/serviceLib/serviceRequests/memory.go @@ -56,7 +56,7 @@ func (r *ServiceRequestListMemoryRegions) Execute() (*serviceWrap.BladeMemoryReg klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "MemoryId", fmt.Sprintf("%+v", *r.MemoryId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if r.AllAppliances() && r.AllBlades() && r.AllMemoryRegions() { summary, err = serviceWrap.GetMemoryRegions_AllApplsAllBlades(serviceClient) @@ -151,42 +151,16 @@ func (r *ServiceRequestListMemoryRegions) OutputSummaryListMemory(s *serviceWrap } type ServiceRequestComposeMemory struct { - serviceTcp *TcpInfo - applianceId *Id - bladeId *Id - portId *Id - resourceSize *Size - qos int32 -} - -//TODO: Should I propogate: private struct variables, forcing Getter usage -and- adding pointer safety to all Getter's (like generated cfm-service client) - -func (r *ServiceRequestComposeMemory) GetServiceIp() string { - return r.serviceTcp.GetIp() -} - -func (r *ServiceRequestComposeMemory) GetServicePort() uint16 { - return r.serviceTcp.GetPort() -} - -func (r *ServiceRequestComposeMemory) GetApplianceId() string { - return r.applianceId.GetId() -} - -func (r *ServiceRequestComposeMemory) GetBladeId() string { - return r.bladeId.GetId() -} - -func (r *ServiceRequestComposeMemory) GetPortId() string { - return r.portId.GetId() -} - -func (r *ServiceRequestComposeMemory) GetResourceSizeGiB() int32 { - return r.resourceSize.GetSizeGiB() + ServiceTcp *TcpInfo + ApplianceId *Id + BladeId *Id + PortId *Id + ResourceSize *Size + Qos int32 } func (r *ServiceRequestComposeMemory) GetQos() int32 { - return r.qos + return r.Qos } func NewServiceRequestComposeMemory(cmd *cobra.Command) *ServiceRequestComposeMemory { @@ -198,25 +172,25 @@ func NewServiceRequestComposeMemory(cmd *cobra.Command) *ServiceRequestComposeMe } return &ServiceRequestComposeMemory{ - serviceTcp: NewTcpInfo(cmd, flags.SERVICE), - applianceId: NewId(cmd, flags.APPLIANCE), - bladeId: NewId(cmd, flags.BLADE), - portId: NewId(cmd, flags.PORT), - resourceSize: NewSize(cmd, flags.RESOURCE), - qos: qos, + ServiceTcp: NewTcpInfo(cmd, flags.SERVICE), + ApplianceId: NewId(cmd, flags.APPLIANCE), + BladeId: NewId(cmd, flags.BLADE), + PortId: NewId(cmd, flags.PORT), + ResourceSize: NewSize(cmd, flags.RESOURCE), + Qos: qos, } } func (r *ServiceRequestComposeMemory) Execute() (*service.MemoryRegion, error) { - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "serviceTcp", fmt.Sprintf("%+v", *r.serviceTcp)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "applianceId", fmt.Sprintf("%+v", *r.applianceId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "bladeId", fmt.Sprintf("%+v", *r.bladeId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "portId", fmt.Sprintf("%+v", *r.portId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "resourceSize", fmt.Sprintf("%+v", r.resourceSize)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "PortId", fmt.Sprintf("%+v", *r.PortId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ResourceSize", fmt.Sprintf("%+v", r.ResourceSize)) - serviceClient := serviceWrap.GetServiceClient(r.GetServiceIp(), r.GetServicePort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) - region, err := serviceWrap.ComposeMemory(serviceClient, r.GetApplianceId(), r.GetBladeId(), r.GetPortId(), r.GetResourceSizeGiB()*1024, r.GetQos()) + region, err := serviceWrap.ComposeMemory(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId(), r.PortId.GetId(), r.ResourceSize.GetSizeGiB()*1024, r.GetQos()) if err != nil { return nil, fmt.Errorf("failure: compose memory: %s", err) } @@ -235,51 +209,31 @@ func (r *ServiceRequestComposeMemory) OutputResultsComposedMemory(m *service.Mem } type ServiceRequestFreeMemory struct { - serviceTcp *TcpInfo - applianceId *Id - bladeId *Id - memoryId *Id -} - -func (r *ServiceRequestFreeMemory) GetServiceIp() string { - return r.serviceTcp.GetIp() -} - -func (r *ServiceRequestFreeMemory) GetServicePort() uint16 { - return r.serviceTcp.GetPort() -} - -func (r *ServiceRequestFreeMemory) GetApplianceId() string { - return r.applianceId.GetId() -} - -func (r *ServiceRequestFreeMemory) GetBladeId() string { - return r.bladeId.GetId() -} - -func (r *ServiceRequestFreeMemory) GetMemoryId() string { - return r.memoryId.GetId() + ServiceTcp *TcpInfo + ApplianceId *Id + BladeId *Id + MemoryId *Id } func NewServiceRequestFreeMemory(cmd *cobra.Command) *ServiceRequestFreeMemory { return &ServiceRequestFreeMemory{ - serviceTcp: NewTcpInfo(cmd, flags.SERVICE), - applianceId: NewId(cmd, flags.APPLIANCE), - bladeId: NewId(cmd, flags.BLADE), - memoryId: NewId(cmd, flags.MEMORY), + ServiceTcp: NewTcpInfo(cmd, flags.SERVICE), + ApplianceId: NewId(cmd, flags.APPLIANCE), + BladeId: NewId(cmd, flags.BLADE), + MemoryId: NewId(cmd, flags.MEMORY), } } func (r *ServiceRequestFreeMemory) Execute() (*service.MemoryRegion, error) { - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "serviceTcp", fmt.Sprintf("%+v", *r.serviceTcp)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "applianceId", fmt.Sprintf("%+v", *r.applianceId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "bladeId", fmt.Sprintf("%+v", *r.bladeId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "memoryId", fmt.Sprintf("%+v", *r.memoryId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "MemoryId", fmt.Sprintf("%+v", *r.MemoryId)) - serviceClient := serviceWrap.GetServiceClient(r.GetServiceIp(), r.GetServicePort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) - region, err := serviceWrap.FreeMemory(serviceClient, r.GetApplianceId(), r.GetBladeId(), r.GetMemoryId()) + region, err := serviceWrap.FreeMemory(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId(), r.MemoryId.GetId()) if err != nil { return nil, fmt.Errorf("failure: free memory: %s", err) } @@ -330,7 +284,7 @@ func (r *ServiceRequestListHostMemoryRegions) Execute() (*serviceWrap.HostMemory klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostId", fmt.Sprintf("%+v", *r.HostId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "MemoryId", fmt.Sprintf("%+v", *r.MemoryId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if r.AllHosts() && r.AllMemoryRegions() { summary, err = serviceWrap.GetMemoryRegions_AllHosts(serviceClient) @@ -401,3 +355,68 @@ func (r *ServiceRequestListHostMemoryRegions) OutputSummaryListMemory(s *service fmt.Printf("\n") } + +// ServiceRequestBladesAssignMemory - This request structure supports BOTH "assign" and "unassign" of a memory region to\from a port +// This is an artifact of the way the cfm-service client api is setup. +type ServiceRequestBladesAssignMemory struct { + ServiceTcp *TcpInfo + ApplianceId *Id + BladeId *Id + MemoryId *Id + PortId *Id + Operation string //"assign" or "unassign" +} + +func NewServiceRequestBladesAssignMemory(cmd *cobra.Command, operation string) *ServiceRequestBladesAssignMemory { + + if operation != "assign" && operation != "unassign" { + newErr := fmt.Errorf("failure: NewServiceRequestBladesAssignMemory: operation options: 'assign', 'unassign'") + klog.ErrorS(newErr, "Invalid parameter value", "operation", operation) + cobra.CheckErr(newErr) + } + + return &ServiceRequestBladesAssignMemory{ + ServiceTcp: NewTcpInfo(cmd, flags.SERVICE), + ApplianceId: NewId(cmd, flags.APPLIANCE), + BladeId: NewId(cmd, flags.BLADE), + MemoryId: NewId(cmd, flags.MEMORY), + PortId: NewId(cmd, flags.PORT), + Operation: operation, + } +} + +func (r *ServiceRequestBladesAssignMemory) GetOperation() string { + return r.Operation +} + +func (r *ServiceRequestBladesAssignMemory) Execute() (*service.MemoryRegion, error) { + var err error + + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.ApplianceId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "MemoryId", fmt.Sprintf("%+v", *r.MemoryId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "PortId", fmt.Sprintf("%+v", *r.PortId)) + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "Operation", r.Operation) + + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) + + region, err := serviceWrap.BladesAssignMemory(serviceClient, r.ApplianceId.GetId(), r.BladeId.GetId(), r.MemoryId.GetId(), r.PortId.GetId(), r.GetOperation()) + if err != nil { + newErr := fmt.Errorf("failure: assign blade memory region to blade port: %w", err) + klog.ErrorS(newErr, "Execute failure", "memoryId", r.MemoryId.GetId(), "portId", r.PortId.GetId(), "applId", r.ApplianceId.GetId(), "bladeId", r.BladeId.GetId()) + return nil, newErr + } + + return region, nil +} + +func (r *ServiceRequestBladesAssignMemory) OutputSummaryBladesAssignMemory(m *service.MemoryRegion) { + fmt.Printf("\n%s Memory and Port Summary\n", strings.ToUpper(r.GetOperation())) + fmt.Printf("Status: %s\n\n", m.GetStatus()) + fmt.Printf("%-15s %-15s %-15s %-25s\n", "Memory ID", "Port ID", "Blade ID", "Appliance ID") + fmt.Printf("%s %s %s %s\n", strings.Repeat("-", 15), strings.Repeat("-", 15), strings.Repeat("-", 15), strings.Repeat("-", 25)) + fmt.Printf("%-15s %-15s %-15s %-25s\n", m.GetId(), m.GetMemoryAppliancePort(), m.GetMemoryBladeId(), m.GetMemoryApplianceId()) + + fmt.Printf("\n") +} diff --git a/cli/pkg/serviceLib/serviceRequests/memoryBlade.go b/cli/pkg/serviceLib/serviceRequests/memoryBlade.go deleted file mode 100644 index e7f6e12..0000000 --- a/cli/pkg/serviceLib/serviceRequests/memoryBlade.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates - -package serviceRequests - -import ( - "cfm/cli/pkg/serviceLib/flags" - "cfm/cli/pkg/serviceLib/serviceWrap" - "fmt" - "strings" - - service "cfm/pkg/client" - - "github.com/spf13/cobra" - "k8s.io/klog/v2" -) - -// ServiceRequestBladesAssignMemory - This request structure supports BOTH "assign" and "unassign" of a memory region to\from a port -// This is an artifact of the way the cfm-service client api is setup. -type ServiceRequestBladesAssignMemory struct { - serviceTcp *TcpInfo - applianceId *Id - bladeId *Id - memoryId *Id - portId *Id - operation string //"assign" or "unassign" -} - -func NewServiceRequestBladesAssignMemory(cmd *cobra.Command, operation string) *ServiceRequestBladesAssignMemory { - - if operation != "assign" && operation != "unassign" { - newErr := fmt.Errorf("Error: NewServiceRequestBladesAssignMemory: operation options: 'assign', 'unassign'") - klog.ErrorS(newErr, "Invalid parameter value", "operation", operation) - cobra.CheckErr(newErr) - } - - return &ServiceRequestBladesAssignMemory{ - serviceTcp: NewTcpInfo(cmd, flags.SERVICE), - applianceId: NewId(cmd, flags.APPLIANCE), - bladeId: NewId(cmd, flags.BLADE), - memoryId: NewId(cmd, flags.MEMORY), - portId: NewId(cmd, flags.PORT), - operation: operation, - } -} - -func (r *ServiceRequestBladesAssignMemory) GetServiceIp() string { - return r.serviceTcp.GetIp() -} - -func (r *ServiceRequestBladesAssignMemory) GetServicePort() uint16 { - return r.serviceTcp.GetPort() -} - -func (r *ServiceRequestBladesAssignMemory) GetApplianceId() string { - return r.applianceId.GetId() -} - -func (r *ServiceRequestBladesAssignMemory) GetBladeId() string { - return r.bladeId.GetId() -} - -func (r *ServiceRequestBladesAssignMemory) GetMemoryId() string { - return r.memoryId.GetId() -} - -func (r *ServiceRequestBladesAssignMemory) GetPortId() string { - return r.portId.GetId() -} - -func (r *ServiceRequestBladesAssignMemory) GetOperation() string { - return r.operation -} - -func (r *ServiceRequestBladesAssignMemory) Execute() (*service.MemoryRegion, error) { - var err error - - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.serviceTcp)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ApplianceId", fmt.Sprintf("%+v", *r.applianceId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.bladeId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "MemoryId", fmt.Sprintf("%+v", *r.memoryId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "PortId", fmt.Sprintf("%+v", *r.portId)) - klog.V(4).InfoS(fmt.Sprintf("%T", *r), "Operation", r.operation) - - serviceClient := serviceWrap.GetServiceClient(r.GetServiceIp(), r.GetServicePort()) - - region, err := serviceWrap.BladesAssignMemory(serviceClient, r.GetApplianceId(), r.GetBladeId(), r.GetMemoryId(), r.GetPortId(), r.GetOperation()) - if err != nil { - newErr := fmt.Errorf("failure: assign blade memory region to blade port: %w", err) - klog.ErrorS(newErr, "Execute failure", "memoryId", r.GetMemoryId(), "portId", r.GetPortId(), "applId", r.GetApplianceId(), "bladeId", r.GetBladeId()) - return nil, newErr - } - - return region, nil -} - -func (r *ServiceRequestBladesAssignMemory) OutputSummaryBladesAssignMemory(m *service.MemoryRegion) { - fmt.Printf("\n%s Memory and Port Summary\n", strings.ToUpper(r.GetOperation())) - fmt.Printf("Status: %s\n\n", m.GetStatus()) - fmt.Printf("%-15s %-15s %-15s %-25s\n", "Memory ID", "Port ID", "Blade ID", "Appliance ID") - fmt.Printf("%s %s %s %s\n", strings.Repeat("-", 15), strings.Repeat("-", 15), strings.Repeat("-", 15), strings.Repeat("-", 25)) - fmt.Printf("%-15s %-15s %-15s %-25s\n", m.GetId(), m.GetMemoryAppliancePort(), m.GetMemoryBladeId(), m.GetMemoryApplianceId()) - - fmt.Printf("\n") -} diff --git a/cli/pkg/serviceLib/serviceRequests/ports.go b/cli/pkg/serviceLib/serviceRequests/ports.go index fd7407f..ccb552f 100644 --- a/cli/pkg/serviceLib/serviceRequests/ports.go +++ b/cli/pkg/serviceLib/serviceRequests/ports.go @@ -53,7 +53,7 @@ func (r *ServiceRequestListBladePorts) Execute() (*serviceWrap.BladePortsSummary klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "PortId", fmt.Sprintf("%+v", *r.PortId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if r.AllAppliances() && r.AllBlades() && r.AllPorts() { summary, err = serviceWrap.GetPorts_AllApplsAllBlades(serviceClient) @@ -179,7 +179,7 @@ func (r *ServiceRequestListHostPorts) Execute() (*serviceWrap.HostPortSummary, e klog.V(4).InfoS(fmt.Sprintf("%T", *r), "HostId", fmt.Sprintf("%+v", *r.HostId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "PortId", fmt.Sprintf("%+v", *r.PortId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if r.AllHosts() && r.AllPorts() { summary, err = serviceWrap.GetAllPorts_AllHosts(serviceClient) diff --git a/cli/pkg/serviceLib/serviceRequests/resources.go b/cli/pkg/serviceLib/serviceRequests/resources.go index 8067c46..d205ec0 100644 --- a/cli/pkg/serviceLib/serviceRequests/resources.go +++ b/cli/pkg/serviceLib/serviceRequests/resources.go @@ -56,7 +56,7 @@ func (r *ServiceRequestListResources) Execute() (*serviceWrap.ResourceBlockSumma klog.V(4).InfoS(fmt.Sprintf("%T", *r), "BladeId", fmt.Sprintf("%+v", *r.BladeId)) klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ResourceId", fmt.Sprintf("%+v", *r.ResourceId)) - serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.ip, r.ServiceTcp.port) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) if r.AllAppliances() && r.AllBlades() && r.AllResources() { summary, err = serviceWrap.GetResourceBlocks_AllApplsAllBlades(serviceClient) diff --git a/cli/pkg/serviceLib/serviceRequests/services.go b/cli/pkg/serviceLib/serviceRequests/services.go index f6c1605..1a858dc 100644 --- a/cli/pkg/serviceLib/serviceRequests/services.go +++ b/cli/pkg/serviceLib/serviceRequests/services.go @@ -24,10 +24,10 @@ func NewServiceRequestListServiceInfo(cmd *cobra.Command) *ServiceRequestListSer } } -func (s *ServiceRequestListServiceInfo) Execute() (*service.ServiceInformation, error) { - klog.V(4).InfoS(fmt.Sprintf("%T", *s), "ServiceTcp", fmt.Sprintf("%+v", *s.ServiceTcp)) +func (r *ServiceRequestListServiceInfo) Execute() (*service.ServiceInformation, error) { + klog.V(4).InfoS(fmt.Sprintf("%T", *r), "ServiceTcp", fmt.Sprintf("%+v", *r.ServiceTcp)) - serviceClient := serviceWrap.GetServiceClient(s.ServiceTcp.GetIp(), s.ServiceTcp.GetPort()) + serviceClient := serviceWrap.GetServiceClient(r.ServiceTcp.GetIp(), r.ServiceTcp.GetPort(), r.ServiceTcp.GetInsecure(), r.ServiceTcp.GetProtocol()) serviceInfo, response, err := serviceClient.DefaultAPI.CfmV1Get(context.Background()).Execute() if err != nil { diff --git a/cli/pkg/serviceLib/serviceWrap/common.go b/cli/pkg/serviceLib/serviceWrap/common.go index 206ec1c..c6bfc57 100644 --- a/cli/pkg/serviceLib/serviceWrap/common.go +++ b/cli/pkg/serviceLib/serviceWrap/common.go @@ -3,29 +3,66 @@ package serviceWrap import ( + "crypto/tls" + "crypto/x509" "encoding/json" "errors" "fmt" + "log" "net/http" "net/netip" + "os" "strings" + "time" + "cfm/cli/pkg/serviceLib/flags" service "cfm/pkg/client" "github.com/google/uuid" "k8s.io/klog/v2" ) -func GetServiceClient(ip string, networkPort uint16) *service.APIClient { +const ( + SEAGATE_CFM_SERVICE_CRT_FILEPATH = "/usr/local/share/ca-certificates/github_com_seagate_cfm-self-signed.crt" +) + +func GetServiceClient(ip string, networkPort uint16, insecure bool, protocol string) *service.APIClient { // Instantiate new configuration using openapi funciton. config := service.NewConfiguration() - // Create, then pass, string for IP Address and Network port like "127.0.0.1:8080" + // Setup config basics config.Host = fmt.Sprintf("%s:%d", ip, networkPort) + config.Scheme = protocol + //TODO: Add this back in?? Check to see where this goes and if the service code is using it // // Pass debug value. // config.Debug = debug + if protocol == flags.PROTOCOL_HTTPS { + caCertPool := x509.NewCertPool() + + if !insecure { + // Load the cfm-service self-signed certificate + caCert, err := os.ReadFile(SEAGATE_CFM_SERVICE_CRT_FILEPATH) + if err != nil { + log.Fatal(err) + } + + caCertPool.AppendCertsFromPEM(caCert) + } + + // Create a custom HTTP client with the certificate pool + config.HTTPClient = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + RootCAs: caCertPool, + InsecureSkipVerify: insecure, + }, + }, + Timeout: 30 * time.Second, + } + } + // This creates an API client, passing it the above configuration, and gathers a pointer to it. serviceClient := service.NewAPIClient(config) diff --git a/cmd/cfm-cli/cmd/composeBlade.go b/cmd/cfm-cli/cmd/composeBlade.go index 242595c..3813631 100644 --- a/cmd/cfm-cli/cmd/composeBlade.go +++ b/cmd/cfm-cli/cmd/composeBlade.go @@ -28,7 +28,7 @@ var composeBladeCmd = &cobra.Command{ request := serviceRequests.NewServiceRequestComposeMemory(cmd) - if request.GetPortId() != "" { + if request.PortId.GetId() != "" { err := common.PromptYesNo(common.WARNING_CXL_HOST_POWER_DOWN) if err != nil { return diff --git a/cmd/cfm-cli/cmd/root.go b/cmd/cfm-cli/cmd/root.go index 5624b4b..9c58eec 100644 --- a/cmd/cfm-cli/cmd/root.go +++ b/cmd/cfm-cli/cmd/root.go @@ -69,10 +69,6 @@ func initCommonPersistentFlags(cmd *cobra.Command) { //Add globally required cfm-service TCPIP connection flags cmd.PersistentFlags().StringP(flags.SERVICE_NET_IP, flags.SERVICE_NET_IP_SH, flags.SERVICE_NET_IP_DFLT, "cfm-service network IP address") cmd.PersistentFlags().Uint16P(flags.SERVICE_NET_PORT, flags.SERVICE_NET_PORT_SH, flags.SERVICE_NET_PORT_DFLT, "cfm-service network port") - - //Currently unused but need default values downstream - cmd.PersistentFlags().Bool(flags.SERVICE_INSECURE, flags.SERVICE_INSECURE_DFLT, "cfm-service insecure connection flag") - cmd.PersistentFlags().MarkHidden(flags.SERVICE_INSECURE) - cmd.PersistentFlags().String(flags.SERVICE_PROTOCOL, flags.SERVICE_PROTOCOL_DFLT, "cfm-service network connection protocol (http/https)") - cmd.PersistentFlags().MarkHidden(flags.SERVICE_PROTOCOL) + cmd.PersistentFlags().BoolP(flags.SERVICE_INSECURE, flags.SERVICE_INSECURE_SH, flags.SERVICE_INSECURE_DFLT, "cfm-service insecure connection flag") + cmd.PersistentFlags().StringP(flags.SERVICE_PROTOCOL, flags.SERVICE_PROTOCOL_SH, flags.SERVICE_PROTOCOL_DFLT, "cfm-service network connection protocol (http/https)") }