diff --git a/client/v3/v3_service.go b/client/v3/v3_service.go index 29457b26f..0621927e8 100644 --- a/client/v3/v3_service.go +++ b/client/v3/v3_service.go @@ -62,6 +62,9 @@ type Service interface { ListAllImage() (*ImageListIntentResponse, error) ListAllCluster() (*ClusterListIntentResponse, error) GetTask(taskUUID string) (*TasksResponse, error) + GetHost(taskUUID string) (*HostResponse, error) + ListHost(getEntitiesRequest *DSMetadata) (*HostListResponse, error) + ListAllHost() (*HostListResponse, error) } /*CreateVM Creates a VM @@ -1067,3 +1070,73 @@ func (op Operations) GetTask(taskUUID string) (*TasksResponse, error) { return tasksTesponse, op.client.Do(ctx, req, tasksTesponse) } + +//GetHost ... +func (op Operations) GetHost(hostUUID string) (*HostResponse, error) { + ctx := context.TODO() + + path := fmt.Sprintf("/hosts/%s", hostUUID) + host := new(HostResponse) + + req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, err + } + + return host, op.client.Do(ctx, req, host) +} + +//ListHost ... +func (op Operations) ListHost(getEntitiesRequest *DSMetadata) (*HostListResponse, error) { + ctx := context.TODO() + path := "/hosts/list" + + hostList := new(HostListResponse) + + req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest) + if err != nil { + return nil, err + } + + return hostList, op.client.Do(ctx, req, hostList) +} + +// ListAllHost ... +func (op Operations) ListAllHost() (*HostListResponse, error) { + entities := make([]*HostResponse, 0) + + resp, err := op.ListHost(&DSMetadata{ + Kind: utils.StringPtr("host"), + Length: utils.Int64Ptr(itemsPerPage), + }) + if err != nil { + return nil, err + } + + totalEntities := utils.Int64Value(resp.Metadata.TotalMatches) + remaining := totalEntities + offset := utils.Int64Value(resp.Metadata.Offset) + + if totalEntities > itemsPerPage { + for hasNext(&remaining) { + resp, err = op.ListHost(&DSMetadata{ + Kind: utils.StringPtr("cluster"), + Length: utils.Int64Ptr(itemsPerPage), + Offset: utils.Int64Ptr(offset), + }) + + if err != nil { + return nil, err + } + + entities = append(entities, resp.Entities...) + + offset += itemsPerPage + log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities)) + } + + resp.Entities = entities + } + + return resp, nil +} diff --git a/client/v3/v3_service_test.go b/client/v3/v3_service_test.go index 7bc54977f..50820e64c 100644 --- a/client/v3/v3_service_test.go +++ b/client/v3/v3_service_test.go @@ -2797,3 +2797,125 @@ func testHTTPMethod(t *testing.T, r *http.Request, expected string) { t.Errorf("Request method = %v, expected %v", r.Method, expected) } } + +func TestOperations_GetHost(t *testing.T) { + mux, c, server := setup() + + defer server.Close() + + mux.HandleFunc("/api/nutanix/v3/hosts/cfde831a-4e87-4a75-960f-89b0148aa2cc", func(w http.ResponseWriter, r *http.Request) { + testHTTPMethod(t, r, http.MethodGet) + fmt.Fprint(w, `{"metadata": {"kind":"host","uuid":"cfde831a-4e87-4a75-960f-89b0148aa2cc"}}`) + }) + + hostResponse := &HostResponse{} + hostResponse.Metadata = &Metadata{ + UUID: utils.StringPtr("cfde831a-4e87-4a75-960f-89b0148aa2cc"), + Kind: utils.StringPtr("host"), + } + + type fields struct { + client *client.Client + } + + type args struct { + UUID string + } + + tests := []struct { + name string + fields fields + args args + want *HostResponse + wantErr bool + }{ + { + "Test GetHost OK", + fields{c}, + args{"cfde831a-4e87-4a75-960f-89b0148aa2cc"}, + hostResponse, + false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + op := Operations{ + client: tt.fields.client, + } + got, err := op.GetHost(tt.args.UUID) + if (err != nil) != tt.wantErr { + t.Errorf("Operations.GetHost() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("Operations.GetHost() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestOperations_ListHost(t *testing.T) { + mux, c, server := setup() + + defer server.Close() + + mux.HandleFunc("/api/nutanix/v3/hosts/list", func(w http.ResponseWriter, r *http.Request) { + testHTTPMethod(t, r, http.MethodPost) + fmt.Fprint(w, `{"entities":[{"metadata": {"kind":"host","uuid":"cfde831a-4e87-4a75-960f-89b0148aa2cc"}}]}`) + }) + + hostList := &HostListResponse{} + hostList.Entities = make([]*HostResponse, 1) + hostList.Entities[0] = &HostResponse{} + hostList.Entities[0].Metadata = &Metadata{ + UUID: utils.StringPtr("cfde831a-4e87-4a75-960f-89b0148aa2cc"), + Kind: utils.StringPtr("host"), + } + + input := &DSMetadata{ + Length: utils.Int64Ptr(1.0), + } + + type fields struct { + client *client.Client + } + + type args struct { + getEntitiesRequest *DSMetadata + } + + tests := []struct { + name string + fields fields + args args + want *HostListResponse + wantErr bool + }{ + { + "Test ListSubnet OK", + fields{c}, + args{input}, + hostList, + false, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + op := Operations{ + client: tt.fields.client, + } + got, err := op.ListHost(tt.args.getEntitiesRequest) + if (err != nil) != tt.wantErr { + t.Errorf("Operations.ListHost() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("Operations.ListHost() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/client/v3/v3_structs.go b/client/v3/v3_structs.go index 5db130376..e4cc1b572 100644 --- a/client/v3/v3_structs.go +++ b/client/v3/v3_structs.go @@ -1795,3 +1795,142 @@ type DeleteStatus struct { State string `json:"state"` ExecutionContext *ExecutionContext `json:"execution_context"` } + +/* Host Resource */ + +// DomainCredencial represents the way to login server +type DomainCredencial struct { + Username string `json:"username,omitempty"` + Password string `json:"password,omitempty"` +} + +// WindowsDomain means Hyper-V node domain +type WindowsDomain struct { + Name string `json:"name,omitempty"` + NameServerIP string `json:"name_server_ip,omitempty"` + OrganizationUnitPath string `json:"organization_unit_path,omitempty"` + NamePrefix string `json:"name_prefix,omitempty"` + DomainName string `json:"domain_name,omitempty"` + DomainCredencial *DomainCredencial `json:"domain_credencial,omitempty"` +} + +// OplogUsage represents oplog disk usage +type OplogUsage struct { + OplogDiskPct *float64 `json:"oplog_disk_pct,omitempty"` + OplogDiskSize *int64 `json:"oplog_disk_size,omitempty"` +} + +// ControllerVM means Hyper-V node domain +type ControllerVM struct { + IP string `json:"ip,omitempty"` + NatIP string `json:"nat_ip,omitempty"` + NatPort *int64 `json:"nat_port,omitempty"` + OplogUsage *OplogUsage `json:"oplog_usage,omitempty"` +} + +// FailoverCluster means Hiper-V failover cluster +type FailoverCluster struct { + IP string `json:"ip,omitempty"` + Name string `json:"name,omitempty"` + DomainCredencial *DomainCredencial `json:"domain_credencial,omitempty"` +} + +// IPMI means Host IPMI Information +type IPMI struct { + IP string `json:"ip,omitempty"` +} + +// ReferenceValues references to a kind +type ReferenceValues struct { + Kind string `json:"kind,omitempty"` + UUID string `json:"uuid,omitempty"` + Name string `json:"name,omitempty"` +} + +// GPU represnts list of GPUs on the host +type GPU struct { + Status string `json:"status,omitempty"` + Vendor string `json:"vendor,omitempty"` + NumVirtualDisplayHeads *int64 `json:"num_virtual_display_heads,omitempty"` + Assignable bool `json:"assignable,omitempty"` + LicenseList []*string `json:"license_list,omitempty"` + NumVgpusAllocated *int64 `json:"num_vgpus_allocated,omitempty"` + PciAddress string `json:"pci_address,omitempty"` + Name string `json:"name,omitempty"` + FrameBufferSizeMib *int64 `json:"frame_buffer_size_mib,omitempty"` + Index *int64 `json:"index,omitempty"` + UUID string `json:"uuid,omitempty"` + NumaNode *int64 `json:"numa_node,omitempty"` + MaxResoution string `json:"max_resolution,omitempty"` + ConsumerReference *ReferenceValues `json:"consumer_reference,omitempty"` + Mode string `json:"mode,omitempty"` + Fraction *int64 `json:"fraction,omitempty"` + GuestDriverVersion string `json:"guest_driver_version,omitempty"` + DeviceID *int64 `json:"device_id,omitempty"` +} + +// Hypervisor Full name of hypervisor running on Host +type Hypervisor struct { + NumVms *int64 `json:"num_vms,omitempty"` + IP string `json:"ip,omitempty"` + HypervisorFullName string `json:"hypervisor_full_name,omitempty"` +} + +// Block represents Host block config info. +type Block struct { + BlockSerialNumber string `json:"block_serial_number,omitempty"` + BlockModel string `json:"block_model,omitempty"` +} + +// HostResources represents the host resources +type HostResources struct { + GPUDriverVersion string `json:"gpu_driver_version,omitempty"` + FailoverCluster *FailoverCluster `json:"failover_cluster,omitempty"` + IPMI *IPMI `json:"ipmi,omitempty"` + CPUModel string `json:"cpu_model,omitempty"` + HostNicsIDList []*string `json:"host_nics_id_list,omitempty"` + NumCPUSockets *int64 `json:"num_cpu_sockets,omitempty"` + WindowsDomain *WindowsDomain `json:"windows_domain,omitempty"` + GPUList []*GPU `json:"gpu_list,omitempty"` + SerialNumber string `json:"serial_number,omitempty"` + CPUCapacityHZ *int64 `json:"cpu_capacity_hz,omitempty"` + MemoryVapacityMib *int64 `json:"memory_capacity_mib,omitempty"` + HostDisksReferenceList []*ReferenceValues `json:"host_disks_reference_list,omitempty"` + MonitoringState string `json:"monitoring_state,omitempty"` + Hypervisor *Hypervisor `json:"hypervisor,omitempty"` + HostType string `json:"host_type,omitempty"` + NumCPUCores *int64 `json:"num_cpu_cores,omitempty"` + RackableUnitReference *ReferenceValues `json:"rackable_unit_reference,omitempty"` + ControllerVM *ControllerVM `json:"controller_vm,omitempty"` + Block *Block `json:"block,omitempty"` +} + +// HostSpec Represents volume group input spec. +type HostSpec struct { + Name string `json:"name,omitempty"` + Resources *HostResources `json:"resources,omitempty"` +} + +// HostStatus Volume group configuration. +type HostStatus struct { + State string `json:"state,omitempty"` + MessageList []*MessageResource `json:"message_list,omitempty"` + Name string `json:"name,omitempty"` + Resources *HostResources `json:"resources,omitempty"` + ClusterReference *ReferenceValues `json:"cluster_reference,omitempty"` +} + +// HostResponse Response object for intentful operations on a Host +type HostResponse struct { + APIVersion string `json:"api_version,omitempty"` + Metadata *Metadata `json:"metadata,omitempty"` + Spec *HostSpec `json:"spec,omitempty"` + Status *HostStatus `json:"status,omitempty"` +} + +// HostListResponse Response object for intentful operation of Host +type HostListResponse struct { + APIVersion string `json:"api_version,omitempty"` + Entities []*HostResponse `json:"entities,omitempty"` + Metadata *ListMetadataOutput `json:"metadata,omitempty"` +} diff --git a/go.mod b/go.mod index 4a3715aed..9ca677e47 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/hashicorp/terraform v0.12.3 github.com/mitchellh/gox v1.0.1 github.com/spf13/afero v1.2.2 // indirect + github.com/spf13/cast v1.3.1 ) go 1.13 diff --git a/go.sum b/go.sum index b37df1a53..c657afb6f 100644 --- a/go.sum +++ b/go.sum @@ -536,6 +536,8 @@ github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/nutanix/data_source_nutanix_host.go b/nutanix/data_source_nutanix_host.go new file mode 100644 index 000000000..bd5b049ee --- /dev/null +++ b/nutanix/data_source_nutanix_host.go @@ -0,0 +1,688 @@ +package nutanix + +import ( + "github.com/spf13/cast" + + "github.com/hashicorp/terraform/helper/schema" + v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3" +) + +func dataSourceNutanixHost() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNutanixHostRead, + Schema: map[string]*schema.Schema{ + "host_id": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "gpu_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "failover_cluster": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_credencial": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "ipmi": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cpu_model": { + Type: schema.TypeString, + Computed: true, + }, + "host_nics_id_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "num_cpu_sockets": { + Type: schema.TypeInt, + Computed: true, + }, + "windows_domain": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "name_server_ip": { + Type: schema.TypeString, + Computed: true, + }, + "organization_unit_path": { + Type: schema.TypeString, + Computed: true, + }, + "name_prefix": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_credencial": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gpu_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vendor": { + Type: schema.TypeString, + Computed: true, + }, + "num_virtual_display_heads": { + Type: schema.TypeInt, + Computed: true, + }, + "assignable": { + Type: schema.TypeBool, + Computed: true, + }, + "license_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "num_vgpus_allocated": { + Type: schema.TypeInt, + Computed: true, + }, + "pci_address": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "frame_buffer_size_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "index": { + Type: schema.TypeInt, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "numa_node": { + Type: schema.TypeInt, + Computed: true, + }, + "max_resolution": { + Type: schema.TypeString, + Computed: true, + }, + "consumer_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "fraction": { + Type: schema.TypeInt, + Computed: true, + }, + "guest_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "device_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "serial_number": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_capacity_hz": { + Type: schema.TypeInt, + Computed: true, + }, + "memory_capacity_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "host_disks_reference_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "monitoring_state": { + Type: schema.TypeString, + Computed: true, + }, + "hypervisor": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "num_vms": { + Type: schema.TypeInt, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "hypervisor_full_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "host_type": { + Type: schema.TypeString, + Computed: true, + }, + "num_cpu_cores": { + Type: schema.TypeInt, + Computed: true, + }, + "rackable_unit_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "controller_vm": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "nat_ip": { + Type: schema.TypeString, + Computed: true, + }, + "oplog_usage": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "opolog_disk_pct": { + Type: schema.TypeFloat, + Computed: true, + }, + "opolog_disk_size": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "nat_port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "block": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "block_serial_number": { + Type: schema.TypeString, + Computed: true, + }, + "block_model": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cluster_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": categoriesSchema(), + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceNutanixHostRead(d *schema.ResourceData, meta interface{}) error { + // Get client connection + conn := meta.(*Client).API + + hostID := d.Get("host_id").(string) + + host, err := conn.V3.GetHost(hostID) + if err != nil { + return err + } + + if err := d.Set("name", host.Status.Name); err != nil { + return err + } + if err := d.Set("gpu_driver_version", host.Status.Resources.GPUDriverVersion); err != nil { + return err + } + if err := d.Set("failover_cluster", flattenFailOverCluster(host.Status.Resources.FailoverCluster)); err != nil { + return err + } + if err := d.Set("ipmi", flattenIMPI(host.Status.Resources.IPMI)); err != nil { + return err + } + if err := d.Set("cpu_model", host.Status.Resources.CPUModel); err != nil { + return err + } + if err := d.Set("host_nics_id_list", host.Status.Resources.HostNicsIDList); err != nil { + return err + } + if err := d.Set("num_cpu_sockets", host.Status.Resources.NumCPUSockets); err != nil { + return err + } + if err := d.Set("windows_domain", flattenWindowsDomain(host.Status.Resources.WindowsDomain)); err != nil { + return err + } + if err := d.Set("gpu_list", flattenGpuList(host.Status.Resources.GPUList)); err != nil { + return err + } + if err := d.Set("serial_number", host.Status.Resources.SerialNumber); err != nil { + return err + } + if err := d.Set("cpu_capacity_hz", host.Status.Resources.CPUCapacityHZ); err != nil { + return err + } + if err := d.Set("memory_capacity_mib", host.Status.Resources.MemoryVapacityMib); err != nil { + return err + } + if err := d.Set("host_disks_reference_list", flattenReferenceList(host.Status.Resources.HostDisksReferenceList)); err != nil { + return err + } + if err := d.Set("monitoring_state", host.Status.Resources.MonitoringState); err != nil { + return err + } + if err := d.Set("hypervisor", flattenHypervisor(host.Status.Resources.Hypervisor)); err != nil { + return err + } + if err := d.Set("host_type", host.Status.Resources.HostType); err != nil { + return err + } + if err := d.Set("num_cpu_cores", host.Status.Resources.NumCPUCores); err != nil { + return err + } + if err := d.Set("rackable_unit_reference", flattenReference(host.Status.Resources.RackableUnitReference)); err != nil { + return err + } + if err := d.Set("controller_vm", flattenControllerVM(host.Status.Resources.ControllerVM)); err != nil { + return err + } + if err := d.Set("block", flattenBlock(host.Status.Resources.Block)); err != nil { + return err + } + if err := d.Set("cluster_reference", flattenReference(host.Status.ClusterReference)); err != nil { + return err + } + m, c := setRSEntityMetadata(host.Metadata) + + if err := d.Set("metadata", m); err != nil { + return err + } + if err := d.Set("categories", c); err != nil { + return err + } + if err := d.Set("project_reference", flattenReferenceValues(host.Metadata.ProjectReference)); err != nil { + return err + } + if err := d.Set("owner_reference", flattenReferenceValues(host.Metadata.OwnerReference)); err != nil { + return err + } + + d.SetId(hostID) + return nil +} + +func flattenFailOverCluster(failOvercluster *v3.FailoverCluster) map[string]interface{} { + if failOvercluster != nil { + return map[string]interface{}{ + "ip": failOvercluster.IP, + "name": failOvercluster.Name, + "domain_credencial": flattenDomainCredencials(failOvercluster.DomainCredencial), + } + } + return map[string]interface{}{} +} + +func flattenDomainCredencials(domainCredencial *v3.DomainCredencial) map[string]interface{} { + if domainCredencial != nil { + return map[string]interface{}{ + "username": domainCredencial.Username, + "password": domainCredencial.Password, + } + } + return map[string]interface{}{} +} + +func flattenIMPI(impi *v3.IPMI) map[string]interface{} { + if impi != nil { + return map[string]interface{}{ + "ip": impi.IP, + } + } + return map[string]interface{}{} +} + +func flattenWindowsDomain(windowsDomain *v3.WindowsDomain) map[string]interface{} { + if windowsDomain != nil { + return map[string]interface{}{ + "name": windowsDomain.Name, + "name_server_ip": windowsDomain.NameServerIP, + "organization_unit_path": windowsDomain.OrganizationUnitPath, + "name_prefix": windowsDomain.NamePrefix, + "domain_name": windowsDomain.DomainCredencial, + "domain_credencial": windowsDomain.DomainCredencial, + } + } + return map[string]interface{}{} +} + +func flattenGpuList(cpuList []*v3.GPU) []map[string]interface{} { + res := make([]map[string]interface{}, len(cpuList)) + if len(cpuList) > 0 { + for i, cpu := range cpuList { + res[i] = map[string]interface{}{ + "status": cpu.Status, + "vendor": cpu.Vendor, + "num_virtual_display_heads": cpu.NumVirtualDisplayHeads, + "assignable": cpu.Assignable, + "license_list": cpu.LicenseList, + "num_vgpus_allocated": cpu.NumVgpusAllocated, + "pci_address": cpu.PciAddress, + "name": cpu.Name, + "frame_buffer_size_mib": cpu.FrameBufferSizeMib, + "index": cpu.Index, + "uuid": cpu.UUID, + "numa_node": cpu.NumaNode, + "max_resolution": cpu.MaxResoution, + "consumer_reference": flattenReference(cpu.ConsumerReference), + "mode": cpu.Mode, + "fraction": cpu.Fraction, + "guest_driver_version": cpu.GuestDriverVersion, + "device_id": cpu.DeviceID, + } + } + } + return res +} + +func flattenReference(reference *v3.ReferenceValues) map[string]interface{} { + if reference != nil { + return map[string]interface{}{ + "kind": reference.Kind, + "uuid": reference.UUID, + "name": reference.Name, + } + } + return map[string]interface{}{} +} + +func flattenReferenceList(references []*v3.ReferenceValues) []map[string]interface{} { + res := make([]map[string]interface{}, len(references)) + if len(references) > 0 { + for i, r := range references { + res[i] = map[string]interface{}{ + "kind": r.Kind, + "uuid": r.UUID, + "name": r.Name, + } + } + } + return res +} + +func flattenHypervisor(hypervisor *v3.Hypervisor) map[string]interface{} { + if hypervisor != nil { + return map[string]interface{}{ + "num_vms": cast.ToString(hypervisor.NumVms), + "ip": hypervisor.IP, + "hypervisor_full_name": hypervisor.HypervisorFullName, + } + } + return map[string]interface{}{} +} + +func flattenControllerVM(controllerVM *v3.ControllerVM) map[string]interface{} { + if controllerVM != nil { + return map[string]interface{}{ + "ip": controllerVM.IP, + "nat_ip": controllerVM.NatIP, + "oplog_usage.opolog_disk_pct": cast.ToString(controllerVM.OplogUsage.OplogDiskPct), + "oplog_usage.opolog_disk_size": cast.ToString(controllerVM.OplogUsage.OplogDiskSize), + "nat_port": controllerVM.NatPort, + } + } + return map[string]interface{}{} +} + +func flattenBlock(block *v3.Block) map[string]interface{} { + if block != nil { + return map[string]interface{}{ + "block_serial_number": block.BlockSerialNumber, + "block_model": block.BlockModel, + } + } + return map[string]interface{}{} +} diff --git a/nutanix/data_source_nutanix_host_test.go b/nutanix/data_source_nutanix_host_test.go new file mode 100644 index 000000000..a66357193 --- /dev/null +++ b/nutanix/data_source_nutanix_host_test.go @@ -0,0 +1,105 @@ +package nutanix + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccNutanixHostDataSource_basic(t *testing.T) { + dataSourceName := "data.nutanix_host.test" + vmResourceName := "nutanix_virtual_machine.vm" + + imgName := fmt.Sprintf("test-acc-dou-image-%s", acctest.RandString(3)) + vmName := fmt.Sprintf("test-acc-dou-vm-%s", acctest.RandString(3)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccHostDataSourceConfig(imgName, vmName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(vmResourceName, "name"), + resource.TestCheckResourceAttrSet(vmResourceName, "cluster_uuid"), + resource.TestCheckResourceAttrSet(vmResourceName, "num_vcpus_per_socket"), + resource.TestCheckResourceAttrSet(vmResourceName, "num_sockets"), + resource.TestCheckResourceAttrSet(vmResourceName, "memory_size_mib"), + resource.TestCheckResourceAttrSet(vmResourceName, "serial_port_list.#"), + resource.TestCheckResourceAttrSet(vmResourceName, "disk_list.#"), + + resource.TestCheckResourceAttr(vmResourceName, "name", vmName), + resource.TestCheckResourceAttr(vmResourceName, "num_vcpus_per_socket", "1"), + resource.TestCheckResourceAttr(vmResourceName, "num_sockets", "1"), + resource.TestCheckResourceAttr(vmResourceName, "memory_size_mib", "186"), + resource.TestCheckResourceAttr(vmResourceName, "serial_port_list.0.index", "1"), + resource.TestCheckResourceAttr(vmResourceName, "serial_port_list.0.is_connected", "true"), + resource.TestCheckResourceAttr(vmResourceName, "disk_list.#", "4"), + + resource.TestCheckResourceAttrSet(dataSourceName, "host_id"), + ), + }, + }, + }) +} + +func testAccHostDataSourceConfig(imgName, vmName string) string { + return fmt.Sprintf(` + data "nutanix_clusters" "clusters" {} + + locals { + cluster1 = "${data.nutanix_clusters.clusters.entities.0.service_list.0 == "PRISM_CENTRAL" + ? data.nutanix_clusters.clusters.entities.1.metadata.uuid : data.nutanix_clusters.clusters.entities.0.metadata.uuid}" + } + + resource "nutanix_image" "cirros-034-disk" { + name = "%s" + source_uri = "http://packages.oit.ncsu.edu/centos/7.7.1908/isos/x86_64/CentOS-7-x86_64-NetInstall-1908.iso" + description = "heres a tiny linux image, not an iso, but a real disk!" + } + + resource "nutanix_virtual_machine" "vm" { + name = "%s" + cluster_uuid = "${local.cluster1}" + + num_vcpus_per_socket = 1 + num_sockets = 1 + memory_size_mib = 186 + + serial_port_list { + index = 1 + is_connected = true + } + + disk_list { + data_source_reference = { + kind = "image" + uuid = "${nutanix_image.cirros-034-disk.id}" + } + + device_properties { + disk_address = { + device_index = 0, + adapter_type = "IDE" + } + device_type = "CDROM" + } + } + disk_list { + disk_size_mib = 100 + } + disk_list { + disk_size_mib = 200 + } + disk_list { + disk_size_mib = 300 + } + } + + data "nutanix_host" "test" { + host_id = nutanix_virtual_machine.vm.host_reference.uuid + } + `, imgName, vmName) +} diff --git a/nutanix/data_source_nutanix_hosts.go b/nutanix/data_source_nutanix_hosts.go new file mode 100644 index 000000000..71d48963f --- /dev/null +++ b/nutanix/data_source_nutanix_hosts.go @@ -0,0 +1,528 @@ +package nutanix + +import ( + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3" +) + +func dataSourceNutanixHosts() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNutanixHostsRead, + Schema: map[string]*schema.Schema{ + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "entities": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "gpu_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "failover_cluster": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_credencial": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "ipmi": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cpu_model": { + Type: schema.TypeString, + Computed: true, + }, + "host_nics_id_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "num_cpu_sockets": { + Type: schema.TypeInt, + Computed: true, + }, + "windows_domain": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "name_server_ip": { + Type: schema.TypeString, + Computed: true, + }, + "organization_unit_path": { + Type: schema.TypeString, + Computed: true, + }, + "name_prefix": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "domain_credencial": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gpu_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vendor": { + Type: schema.TypeString, + Computed: true, + }, + "num_virtual_display_heads": { + Type: schema.TypeInt, + Computed: true, + }, + "assignable": { + Type: schema.TypeBool, + Computed: true, + }, + "license_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "num_vgpus_allocated": { + Type: schema.TypeInt, + Computed: true, + }, + "pci_address": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "frame_buffer_size_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "index": { + Type: schema.TypeInt, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "numa_node": { + Type: schema.TypeInt, + Computed: true, + }, + "max_resolution": { + Type: schema.TypeString, + Computed: true, + }, + "consumer_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "fraction": { + Type: schema.TypeInt, + Computed: true, + }, + "guest_driver_version": { + Type: schema.TypeString, + Computed: true, + }, + "device_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "serial_number": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_capacity_hz": { + Type: schema.TypeInt, + Computed: true, + }, + "memory_capacity_mib": { + Type: schema.TypeInt, + Computed: true, + }, + "host_disks_reference_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "monitoring_state": { + Type: schema.TypeString, + Computed: true, + }, + "hypervisor": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "num_vms": { + Type: schema.TypeInt, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "hypervisor_full_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "host_type": { + Type: schema.TypeString, + Computed: true, + }, + "num_cpu_cores": { + Type: schema.TypeInt, + Computed: true, + }, + "rackable_unit_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "controller_vm": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "nat_ip": { + Type: schema.TypeString, + Computed: true, + }, + "oplog_usage": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "opolog_disk_pct": { + Type: schema.TypeFloat, + Computed: true, + }, + "opolog_disk_size": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "nat_port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "block": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "block_serial_number": { + Type: schema.TypeString, + Computed: true, + }, + "block_model": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cluster_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "api_version": { + Type: schema.TypeString, + Computed: true, + }, + "metadata": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_update_time": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "spec_version": { + Type: schema.TypeString, + Computed: true, + }, + "spec_hash": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "categories": categoriesSchema(), + "project_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "owner_reference": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceNutanixHostsRead(d *schema.ResourceData, meta interface{}) error { + // Get client connection + conn := meta.(*Client).API + + resp, err := conn.V3.ListAllHost() + if err != nil { + return err + } + + if err := d.Set("api_version", resp.APIVersion); err != nil { + return err + } + if err := d.Set("entities", flattenHostEntities(resp.Entities)); err != nil { + return err + } + + d.SetId(resource.UniqueId()) + return nil +} + +func flattenHostEntities(hosts []*v3.HostResponse) []map[string]interface{} { + entities := make([]map[string]interface{}, len(hosts)) + + for i, host := range hosts { + metadata, categories := setRSEntityMetadata(host.Metadata) + + entities[i] = map[string]interface{}{ + "name": host.Status.Name, + "gpu_driver_version": host.Status.Resources.GPUDriverVersion, + "failover_cluster": flattenFailOverCluster(host.Status.Resources.FailoverCluster), + "ipmi": flattenIMPI(host.Status.Resources.IPMI), + "cpu_model": host.Status.Resources.CPUModel, + "host_nics_id_list": host.Status.Resources.HostNicsIDList, + "num_cpu_sockets": host.Status.Resources.NumCPUSockets, + "windows_domain": flattenWindowsDomain(host.Status.Resources.WindowsDomain), + "gpu_list": flattenGpuList(host.Status.Resources.GPUList), + "serial_number": host.Status.Resources.SerialNumber, + "cpu_capacity_hz": host.Status.Resources.CPUCapacityHZ, + "memory_capacity_mib": host.Status.Resources.MemoryVapacityMib, + "host_disks_reference_list": flattenReferenceList(host.Status.Resources.HostDisksReferenceList), + "monitoring_state": host.Status.Resources.MonitoringState, + "hypervisor": flattenHypervisor(host.Status.Resources.Hypervisor), + "host_type": host.Status.Resources.HostType, + "num_cpu_cores": host.Status.Resources.NumCPUCores, + "rackable_unit_reference": flattenReference(host.Status.Resources.RackableUnitReference), + "controller_vm": flattenControllerVM(host.Status.Resources.ControllerVM), + "block": flattenBlock(host.Status.Resources.Block), + "cluster_reference": flattenReference(host.Status.ClusterReference), + "metadata": metadata, + "categories": categories, + "project_reference": flattenReferenceValues(host.Metadata.ProjectReference), + "owner_reference": flattenReferenceValues(host.Metadata.OwnerReference), + "api_version": host.APIVersion, + } + } + return entities +} diff --git a/nutanix/data_source_nutanix_hosts_test.go b/nutanix/data_source_nutanix_hosts_test.go new file mode 100644 index 000000000..8ac09efb4 --- /dev/null +++ b/nutanix/data_source_nutanix_hosts_test.go @@ -0,0 +1,25 @@ +package nutanix + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccNutanixHostsDataSource_basic(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccHostsDataSourceConfig(), + }, + }, + }) +} + +func testAccHostsDataSourceConfig() string { + return ` + data "nutanix_hosts" "test" {} + ` +} diff --git a/nutanix/provider.go b/nutanix/provider.go index 90ce066f5..c0a92eabe 100644 --- a/nutanix/provider.go +++ b/nutanix/provider.go @@ -84,6 +84,8 @@ func Provider() terraform.ResourceProvider { "nutanix_virtual_machine": dataSourceNutanixVirtualMachine(), "nutanix_category_key": dataSourceNutanixCategoryKey(), "nutanix_network_security_rule": dataSourceNutanixNetworkSecurityRule(), + "nutanix_host": dataSourceNutanixHost(), + "nutanix_hosts": dataSourceNutanixHosts(), // "nutanix_volume_group": dataSourceNutanixVolumeGroup(), // "nutanix_volume_groups": dataSourceNutanixVolumeGroups(), }, diff --git a/vendor/github.com/spf13/cast/.travis.yml b/vendor/github.com/spf13/cast/.travis.yml index 6420d1c27..833a48799 100644 --- a/vendor/github.com/spf13/cast/.travis.yml +++ b/vendor/github.com/spf13/cast/.travis.yml @@ -4,6 +4,7 @@ env: sudo: required go: - "1.11.x" + - "1.12.x" - tip os: - linux diff --git a/vendor/github.com/spf13/cast/Makefile b/vendor/github.com/spf13/cast/Makefile index 7ccf8930b..f01a5dbb6 100644 --- a/vendor/github.com/spf13/cast/Makefile +++ b/vendor/github.com/spf13/cast/Makefile @@ -1,4 +1,4 @@ -# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +GOVERSION := $(shell go version | cut -d ' ' -f 3 | cut -d '.' -f 2) .PHONY: check fmt lint test test-race vet test-cover-html help .DEFAULT_GOAL := help @@ -12,11 +12,13 @@ test-race: ## Run tests with race detector go test -race ./... fmt: ## Run gofmt linter +ifeq "$(GOVERSION)" "12" @for d in `go list` ; do \ if [ "`gofmt -l -s $$GOPATH/src/$$d | tee /dev/stderr`" ]; then \ echo "^ improperly formatted go files" && echo && exit 1; \ fi \ done +endif lint: ## Run golint linter @for d in `go list` ; do \ diff --git a/vendor/github.com/spf13/cast/caste.go b/vendor/github.com/spf13/cast/caste.go index 75ef32c8d..70c7291be 100644 --- a/vendor/github.com/spf13/cast/caste.go +++ b/vendor/github.com/spf13/cast/caste.go @@ -819,15 +819,15 @@ func ToStringE(i interface{}) (string, error) { case int8: return strconv.FormatInt(int64(s), 10), nil case uint: - return strconv.FormatInt(int64(s), 10), nil + return strconv.FormatUint(uint64(s), 10), nil case uint64: - return strconv.FormatInt(int64(s), 10), nil + return strconv.FormatUint(uint64(s), 10), nil case uint32: - return strconv.FormatInt(int64(s), 10), nil + return strconv.FormatUint(uint64(s), 10), nil case uint16: - return strconv.FormatInt(int64(s), 10), nil + return strconv.FormatUint(uint64(s), 10), nil case uint8: - return strconv.FormatInt(int64(s), 10), nil + return strconv.FormatUint(uint64(s), 10), nil case []byte: return string(s), nil case template.HTML: @@ -1131,19 +1131,14 @@ func ToStringSliceE(i interface{}) ([]string, error) { return v, nil case string: return strings.Fields(v), nil - case []error: - for _, err := range i.([]error) { - a = append(a, err.Error()) - } - return a, nil case interface{}: str, err := ToStringE(v) if err != nil { - return a, fmt.Errorf("unable to cast %#v of type %T to []stringggg", i, i) + return a, fmt.Errorf("unable to cast %#v of type %T to []string", i, i) } return []string{str}, nil default: - return a, fmt.Errorf("unable to cast %#v of type %T to []stringgg", i, i) + return a, fmt.Errorf("unable to cast %#v of type %T to []string", i, i) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 6c86f7728..3066fa154 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -368,7 +368,7 @@ github.com/sourcegraph/go-diff/diff # github.com/spf13/afero v1.2.2 github.com/spf13/afero github.com/spf13/afero/mem -# github.com/spf13/cast v1.3.0 +# github.com/spf13/cast v1.3.1 github.com/spf13/cast # github.com/spf13/cobra v0.0.5 github.com/spf13/cobra