diff --git a/examples/Authentication.md b/examples/Authentication.md new file mode 100644 index 0000000000..e7dd63b820 --- /dev/null +++ b/examples/Authentication.md @@ -0,0 +1,60 @@ +### Authentication guide + +``` go +package example + +import ( + "context" + "os" + "log" + "fmt" + intersight "github.com/CiscoDevNet/intersight-go" +) + + +func SetInputs(config *Config) (context.Context, error) { + ctx := context.Background() + httpSigningInfo := new(intersight.HttpSignatureAuth) + httpSigningInfo.KeyId = config.ApiKey + httpSigningInfo.PrivateKeyPath = config.SecretKey + httpSigningInfo.SigningScheme = intersight.HttpSigningSchemeRsaSha256 + httpSigningInfo.SigningAlgorithm = intersight.HttpSigningAlgorithmRsaPKCS1v15 + httpSigningInfo.SignedHeaders = []string{intersight.HttpSignatureParameterRequestTarget, + "Host", + "Date", + "Digest", + } + if _, err := os.Stat(config.SecretKey); err != nil { + err = httpSigningInfo.SetPrivateKey(config.SecretKey) + if err != nil { + return nil, err + } + } else { + httpSigningInfo.PrivateKeyPath = config.SecretKey + } + + ctx, err := httpSigningInfo.ContextWithValue(ctx) + if err != nil { + fmt.Println(err) + log.Fatal("Error creating authentication context") + } + + return ctx, nil +} + +func getApiClient(config *Config) *Config { + + ctx, err := SetInputs(config) + if err != nil { + log.Printf("Error: ", err) + log.Fatal("Error in authentication context") + } + config.ctx = ctx + cfg := intersight.NewConfiguration() + cfg.Host = config.Endpoint + cfg.Debug = true + apiClient := intersight.NewAPIClient(cfg) + config.ApiClient = apiClient + return config +} +``` diff --git a/examples/BootPolicyCreateUpdate.md b/examples/BootPolicyCreateUpdate.md new file mode 100644 index 0000000000..155df8d70b --- /dev/null +++ b/examples/BootPolicyCreateUpdate.md @@ -0,0 +1,152 @@ +### Example to create boot precision policy + +``` go + +package example + +import ( + "fmt" + "os" + "log" + intersight "github.com/CiscoDevNet/intersight-go" +) + + +func createBootLocalCdd() *intersight.BootDeviceBase { + bootLocalCdd := intersight.NewBootDeviceBase("boot.LocalCdd", "boot.LocalCdd") + bootLocalCdd.SetName("local_cdd1") + bootLocalCdd.SetEnabled(true) + return bootLocalCdd +} + +func createBootLocalDisk() *intersight.BootDeviceBase { + bootLocalDisk := intersight.NewBootDeviceBase("boot.LocalDisk", "boot.LocalDisk") + bootLocalDisk.SetName("local_disk1") + bootLocalDisk.SetEnabled(true) + return bootLocalDisk +} + +func createBootSdcard() *intersight.BootDeviceBase { + bootSdcard := intersight.NewBootDeviceBase("boot.SdCard", "boot.SdCard") + bootSdcard.SetName("boot_sdcard_test") + bootSdcard.SetEnabled(true) + return bootSdcard +} + +func createBootIscsi() *intersight.BootDeviceBase { + bootIscsi := intersight.NewBootDeviceBase("boot.Iscsi", "boot.Iscsi") + bootIscsi.SetName("boot_iscsi_test") + bootIscsi.SetEnabled(true) + return bootIscsi +} + +func createBootVirtualMedia() *intersight.BootDeviceBase { + bootVirtualMedia := intersight.NewBootDeviceBase("boot.VirtualMedia", "boot.VirtualMedia") + bootVirtualMedia.SetName("boot_virtual_media_test") + bootVirtualMedia.SetEnabled(true) + return bootVirtualMedia +} + + +func getOrganizationRelationship(moid string) intersight.OrganizationOrganizationRelationship { + organization := new(intersight.OrganizationOrganization) + organization.ClassId = "mo.MoRef" + organization.ObjectType = "organization.Organization" + organization.Moid = &moid + organizationRelationship := intersight.OrganizationOrganizationAsOrganizationOrganizationRelationship(organization) + return organizationRelationship +} + +func CreateObject(config *Config) { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + + // Get Organization MOID + org_resp, r, org_err := apiClient.OrganizationApi.GetOrganizationOrganizationList(ctx).Filter("Name eq 'default'").Execute() + if org_err != nil { + log.Printf("Error: %v\n", err) + log.Printf("HTTP response: %v\n", r) + return + } + org_list := org_resp.OrganizationOrganizationList.GetResults() + if len(org_list) == 0 { + log.Printf("Couldn't find the organization specified") + return + } + org_moid := org_list[0].MoBaseMo.GetMoid() + + bootLocalCdd := createBootLocalCdd() + bootLocalDisk := createBootLocalDisk() + organizationRelationship := getOrganizationRelationship(org_moid) + bootDevices := []intersight.BootDeviceBase{*bootLocalDisk, *bootLocalCdd} + bootPrecisionPolicy := intersight.NewBootPrecisionPolicyWithDefaults() + bootPrecisionPolicy.SetName("sample_boot_policy1") + bootPrecisionPolicy.SetDescription("sample boot precision policy") + bootPrecisionPolicy.SetBootDevices(bootDevices) + bootPrecisionPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, r, err := apiClient.BootApi.CreateBootPrecisionPolicy(ctx).BootPrecisionPolicy(*bootPrecisionPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Printf("Error: %v\n", err) + log.Printf("HTTP response: %v\n", r) + return + } + fmt.Fprintf(os.Stdout, "Response: %v\n", resp) + + //Update + id := resp.GetMoid() + getapiResponse, r, err := apiClient.BootApi.GetBootPrecisionPolicyByMoid(ctx, id).Execute() + if err != nil { + log.Printf("Error -> GetBootPrecisionPolicyByMoid: %v\n", err) + log.Printf("HTTP response: %v\n", r) + return + } + objMoid := getapiResponse.GetMoid() + organizationMoid := getapiResponse.GetOrganization().MoMoRef.GetMoid() + bootSdcard := createBootSdcard() + bootIscsi := createBootIscsi() + organizationRelationship1 := getOrganizationRelationship(organizationMoid) + bootDevices1 := []intersight.BootDeviceBase{*bootSdcard, *bootIscsi} + updatebootPrecisionPolicy := intersight.NewBootPrecisionPolicyWithDefaults() + updatebootPrecisionPolicy.SetName("updated_boot_precision_policy_for_go_test") + updatebootPrecisionPolicy.SetDescription("updated description of boot precision policy for testing go example") + updatebootPrecisionPolicy.SetBootDevices(bootDevices1) + updatebootPrecisionPolicy.SetOrganization(organizationRelationship1) + updateResp, r, err := apiClient.BootApi.UpdateBootPrecisionPolicy(ctx, objMoid).BootPrecisionPolicy(*updatebootPrecisionPolicy).IfMatch(ifMatch).Execute() + if err != nil { + log.Printf("Error -> UpdateBootPrecisionPolicy: %v\n", err) + log.Printf("HTTP response: %v\n", r) + return + } + fmt.Fprintf(os.Stdout, "Response : %v\n", updateResp) + + //Patch + bootVirtualMedia := createBootVirtualMedia() + bootDevices2 := []intersight.BootDeviceBase{*bootVirtualMedia} + patchbootPrecisionPolicy := intersight.NewBootPrecisionPolicyWithDefaults() + patchbootPrecisionPolicy.SetName("updated_boot_precision_policy_using_patch_go_test") + patchbootPrecisionPolicy.SetDescription("update the description of boot precision policy with patch for go test") + patchbootPrecisionPolicy.SetBootDevices(bootDevices2) + patchbootPrecisionPolicy.SetOrganization(organizationRelationship1) + patchResp, r, err := apiClient.BootApi.PatchBootPrecisionPolicy(ctx, objMoid).BootPrecisionPolicy(*patchbootPrecisionPolicy).IfMatch(ifMatch).Execute() + if err != nil { + log.Printf("Error -> PatchBootPrecisionPolicy: %v\n", err) + log.Printf("HTTP response: %v\n", r) + return + } + fmt.Fprintf(os.Stdout, "Response : %v\n", patchResp) + + //Delete + fullResp, err := apiClient.BootApi.DeleteBootPrecisionPolicy(ctx, objMoid).Execute() + if err != nil { + log.Printf("Error -> DeleteBootPrecisionPolicy: %v\n", err) + log.Printf("HTTP response: %v\n", fullResp) + return + } + +} +``` diff --git a/examples/GetApiExample.md b/examples/GetApiExample.md new file mode 100644 index 0000000000..8bac0e1c80 --- /dev/null +++ b/examples/GetApiExample.md @@ -0,0 +1,25 @@ +### Example to ge the list of SMTP Policies + +``` go +package example + +import ( + "fmt" + "log" + "os" +) + +func GetObjectList(config *Config) { + + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + apiResponse, r, err := apiClient.SmtpApi.GetSmtpPolicyList(ctx).Execute() + if err != nil { + log.Printf("Error when calling `SmtpApi.GetSmtpPolicyList``: %v\n", err) + log.Printf("Full HTTP response: %v\n", r) + return + } + fmt.Fprintf(os.Stdout, "Response from `SmtpApi.GetSmtpPolicyList`: %v\n", apiResponse) +} +``` diff --git a/examples/GetApiWithFilter.md b/examples/GetApiWithFilter.md new file mode 100644 index 0000000000..355f7b8e0f --- /dev/null +++ b/examples/GetApiWithFilter.md @@ -0,0 +1,33 @@ +### Example for GET API with filter + +``` go +package example + +import ( + "fmt" + "log" + "os" +) + +func GetObjectListWithFilter(config *Config) { + filter := "CreateTime gt 2021-08-29T21:58:33Z" + orderby := "CreateTime" + top := int32(5) + skip := int32(1) + select_ := "CreateTime,ModTime" + count := false + inlinecount := "allpages" + + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + apiResponse, r, err := apiClient.ComputeApi.GetComputeRackUnitList(ctx).Filter(filter).Orderby(orderby).Top(top).Skip(skip).Select_(select_).Count(count).Inlinecount(inlinecount).Execute() + if err != nil { + log.Printf("Error when calling `ComputeApi.GetComputeRckUnitList``: %v\n", err) + log.Printf("Full HTTP response: %v\n", r) + return + } + + fmt.Fprintf(os.Stdout, "Response from `ComputeApi.GetComputeRckUnitList`: %v\n", apiResponse) +} +``` diff --git a/examples/policies/adapterConfigPolicy.md b/examples/policies/adapterConfigPolicy.md new file mode 100644 index 0000000000..a7210f2839 --- /dev/null +++ b/examples/policies/adapterConfigPolicy.md @@ -0,0 +1,65 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func setEth() intersight.AdapterEthSettings { + eth := intersight.NewAdapterEthSettings("adapter.EthSettings", "adapter.EthSettings") + eth.SetLldpEnabled(true) + return *eth +} + +func setFc() intersight.AdapterFcSettings { + fc := intersight.NewAdapterFcSettings("adapter.FcSettings", "adapter.FcSettings") + fc.SetFipEnabled(true) + return *fc +} + +func setSettings() *intersight.AdapterAdapterConfig { + adapterConfig := intersight.NewAdapterAdapterConfigWithDefaults() + ethSettings := setEth() + fcSettings := setFc() + adapterConfig.SetSlotId("1") + adapterConfig.SetEthSettings(ethSettings) + adapterConfig.SetFcSettings(fcSettings) + return adapterConfig +} + +func setSettingsMlom() *intersight.AdapterAdapterConfig { + adapterConfig := intersight.NewAdapterAdapterConfigWithDefaults() + ethSettings := setEth() + fcSettings := setFc() + adapterConfig.SetSlotId("MLOM") + adapterConfig.SetEthSettings(ethSettings) + adapterConfig.SetFcSettings(fcSettings) + return adapterConfig +} + + +func CreateAdapterPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + settings := setSettings() + settingsMlom := setSettingsMlom() + settingsArr := []intersight.AdapterAdapterConfig{*settings, *settingsMlom} + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + adapterConfigPolicy := intersight.NewAdapterConfigPolicyWithDefaults() + adapterConfigPolicy.SetSettings(settingsArr) + adapterConfigPolicy.SetName("tf_adapter_config_sdk") + adapterConfigPolicy.SetDescription("test policy") + adapterConfigPolicy.SetOrganization(organizationRelationship) + resp, _, err := apiClient.AdapterApi.CreateAdapterConfigPolicy(ctx).AdapterConfigPolicy(*adapterConfigPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/apiClient.md b/examples/policies/apiClient.md new file mode 100644 index 0000000000..cb3dcec634 --- /dev/null +++ b/examples/policies/apiClient.md @@ -0,0 +1,61 @@ +#### Example to create policy +``` +package policy + +import ( + "context" + "fmt" + "log" + "os" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func SetInputs(config *Config) (context.Context, error) { + ctx := context.Background() + httpSigningInfo := new(intersight.HttpSignatureAuth) + httpSigningInfo.KeyId = config.ApiKey + httpSigningInfo.PrivateKeyPath = config.SecretKey + httpSigningInfo.SigningScheme = intersight.HttpSigningSchemeRsaSha256 + httpSigningInfo.SigningAlgorithm = intersight.HttpSigningAlgorithmRsaPKCS1v15 + httpSigningInfo.SignedHeaders = []string{intersight.HttpSignatureParameterRequestTarget, + // intersight.HttpSignatureParameterCreated, + // intersight.HttpSignatureParameterExpires, + "Host", + "Date", + "Digest", + } + if _, err := os.Stat(config.SecretKey); err != nil { + err = httpSigningInfo.SetPrivateKey(config.SecretKey) + if err != nil { + return nil, err + } + } else { + httpSigningInfo.PrivateKeyPath = config.SecretKey + } + + ctx, err := httpSigningInfo.ContextWithValue(ctx) + if err != nil { + fmt.Println(err) + log.Fatal("Error creating authentication context") + } + + return ctx, nil +} + +func getApiClient(config *Config) *Config { + + ctx, err := SetInputs(config) + if err != nil { + log.Printf("Error: ", err) + log.Fatal("Error in authentication context") + } + config.ctx = ctx + cfg := intersight.NewConfiguration() + cfg.Host = config.Endpoint + cfg.Debug = true + apiClient := intersight.NewAPIClient(cfg) + config.ApiClient = apiClient + return config +} +``` diff --git a/examples/policies/bash_script.sh b/examples/policies/bash_script.sh new file mode 100644 index 0000000000..4456daf18b --- /dev/null +++ b/examples/policies/bash_script.sh @@ -0,0 +1,4 @@ +# Rename all *.txt to *.text +for file in *.go; do + mv -- "$file" "${file%.go}.md" +done diff --git a/examples/policies/createIamEndPointUser.md b/examples/policies/createIamEndPointUser.md new file mode 100644 index 0000000000..4f5c187677 --- /dev/null +++ b/examples/policies/createIamEndPointUser.md @@ -0,0 +1,44 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateIamEndPointUserPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + userPolicy := intersight.NewIamEndPointUserPolicyWithDefaults() + userPolicy.PolicyAbstractPolicy.SetName("iam_end_point_user_policy_test") + userPolicy.PolicyAbstractPolicy.SetDescription("test user policy") + + passwordPropertiesVal := intersight.NewIamEndPointPasswordPropertiesWithDefaults() + passwordPropertiesVal.SetEnforceStrongPassword(true) + passwordPropertiesVal.SetEnablePasswordExpiry(true) + passwordPropertiesVal.SetPasswordExpiryDuration(int64(50)) + passwordPropertiesVal.SetPasswordHistory(int64(5)) + passwordPropertiesVal.SetNotificationPeriod(int64(1)) + passwordPropertiesVal.SetGracePeriod(int64(2)) + passproperties := intersight.NewNullableIamEndPointPasswordProperties(passwordPropertiesVal) + passwordProperties := passproperties.Get() + userPolicy.SetPasswordProperties(*passwordProperties) + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + userPolicy.SetOrganization(organizationRelationship) + + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.IamApi.CreateIamEndPointUserPolicy(ctx).IamEndPointUserPolicy(*userPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/createStorageDriveGroup.md b/examples/policies/createStorageDriveGroup.md new file mode 100644 index 0000000000..9cb63b775e --- /dev/null +++ b/examples/policies/createStorageDriveGroup.md @@ -0,0 +1,85 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func createSpanGroup() *intersight.StorageSpanDrives { + spanGroup := intersight.NewStorageSpanDrives("storage.SpanDrives","storage.SpanDrives") + spanGroup.SetSlots("2") + return spanGroup +} + +func createVirtualDrivePolicy() *intersight.StorageVirtualDrivePolicy { + virtualDrivePolicy := intersight.NewStorageVirtualDrivePolicy("storage.VirtualDrivePolicy", "storage.VirtualDrivePolicy") + virtualDrivePolicy.SetStripSize(int32(64)) + virtualDrivePolicy.SetWritePolicy("Default") + virtualDrivePolicy.SetReadPolicy("Default") + virtualDrivePolicy.SetAccessPolicy("Default") + virtualDrivePolicy.SetDriveCache("Default") + return virtualDrivePolicy +} + +func createStoragePolicyRelationship(moid string) intersight.StorageStoragePolicyRelationship { + storagePolicy := new(intersight.StorageStoragePolicy) + storagePolicy.ClassId = "mo.MoRef" + storagePolicy.ObjectType = "storage.StoragePolicy" + storagePolicy.Moid = &moid + storageRelationship := intersight.StorageStoragePolicyAsStorageStoragePolicyRelationship(storagePolicy) + return storageRelationship +} + +func CreateSorageDriveGroup(config *Config, storageMoid string) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + storageDriveGroup := intersight.NewStorageDriveGroupWithDefaults() + storageDriveGroup.SetName("storage_drive_gp_test") + storageDriveGroup.SetRaidLevel("Raid0") + storageDriveGroup.SetType(int32(0)) + spanGroup1 := createSpanGroup() + spanGroups := []intersight.StorageSpanDrives{*spanGroup1} + storageManualDriveGroup := intersight.NewStorageManualDriveGroupWithDefaults() + storageManualDriveGroup.SetSpanGroups(spanGroups) + manualDriveGroup := intersight.NewNullableStorageManualDriveGroup(storageManualDriveGroup) + manualDriveGroup1 := manualDriveGroup.Get() + storageDriveGroup.SetManualDriveGroup(*manualDriveGroup1) + + virtualDrivePolicy1 := createVirtualDrivePolicy() + virtualPolicy := intersight.NewNullableStorageVirtualDrivePolicy(virtualDrivePolicy1) + virtualPolicy1 := virtualPolicy.Get() + + virtualDrive1 := intersight.NewStorageVirtualDriveConfigurationWithDefaults() + virtualDrive1.SetName("drive_gp_vd") + virtualDrive1.SetSize(int64(100)) + virtualDrive1.SetExpandToAvailable(false) + virtualDrive1.SetBootDrive(false) + virtualDrive1.SetVirtualDrivePolicy(*virtualPolicy1) + + virtualDrive2 := intersight.NewStorageVirtualDriveConfigurationWithDefaults() + virtualDrive2.SetName("drive_gp_vd_01") + virtualDrive2.SetSize(int64(100)) + virtualDrive2.SetExpandToAvailable(false) + virtualDrive2.SetBootDrive(false) + virtualDrive2.SetVirtualDrivePolicy(*virtualPolicy1) + virtualDrives := []intersight.StorageVirtualDriveConfiguration{*virtualDrive1, *virtualDrive2} + storageDriveGroup.SetVirtualDrives(virtualDrives) + + storagePolicyRelationship := createStoragePolicyRelationship(storageMoid) + storageDriveGroup.SetStoragePolicy(storagePolicyRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.StorageApi.CreateStorageDriveGroup(ctx).StorageDriveGroup(*storageDriveGroup).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/createStorageStoragePolicy.md b/examples/policies/createStorageStoragePolicy.md new file mode 100644 index 0000000000..9f72d63516 --- /dev/null +++ b/examples/policies/createStorageStoragePolicy.md @@ -0,0 +1,42 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateStorageStoragePolicy(config *Config) string{ + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + storageStoragePolicy := intersight.NewStorageStoragePolicyWithDefaults() + storageStoragePolicy.PolicyAbstractPolicy.SetName("storage_policy_test") + storageStoragePolicy.PolicyAbstractPolicy.SetDescription( "storage policy test") + storageStoragePolicy.SetUseJbodForVdCreation(true) + storageStoragePolicy.SetUnusedDisksState("UnconfiguredGood") + storageStoragePolicy.SetGlobalHotSpares("3") + + m2VirtualDrive := intersight.NewStorageM2VirtualDriveConfigWithDefaults() + m2VirtualDrive.SetEnable(false) + m2VirtualDrive1 := intersight.NewNullableStorageM2VirtualDriveConfig(m2VirtualDrive) + m2Virtual1 := m2VirtualDrive1.Get() + storageStoragePolicy.SetM2VirtualDrive(*m2Virtual1) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + storageStoragePolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.StorageApi.CreateStorageStoragePolicy(ctx).StorageStoragePolicy(*storageStoragePolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/deviceConnectorPolicy.md b/examples/policies/deviceConnectorPolicy.md new file mode 100644 index 0000000000..a0b1168e86 --- /dev/null +++ b/examples/policies/deviceConnectorPolicy.md @@ -0,0 +1,30 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + + +func CreateDeviceConnectorPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + deviceConnectorPolicy := intersight.NewDeviceconnectorPolicyWithDefaults() + deviceConnectorPolicy.SetOrganization(organizationRelationship) + deviceConnectorPolicy.SetLockoutEnabled(true) + deviceConnectorPolicy.SetName("device_con1_sdk") + deviceConnectorPolicy.SetDescription("test policy") + resp, _, err := apiClient.DeviceconnectorApi.CreateDeviceconnectorPolicy(ctx).DeviceconnectorPolicy(*deviceConnectorPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/idap.md b/examples/policies/idap.md new file mode 100644 index 0000000000..44345c5f71 --- /dev/null +++ b/examples/policies/idap.md @@ -0,0 +1,60 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + + +func setBaseProperties() intersight.IamLdapBaseProperties { + ldapBaseProperties := intersight.NewIamLdapBasePropertiesWithDefaults() + ldapBaseProperties.SetAttribute("CiscoAvPair") + ldapBaseProperties.SetBaseDn("DC=QATCSLABTPI02,DC=cisco,DC=com") + ldapBaseProperties.SetBindDn("CN=administrator,CN=Users,DC=QATCSLABTPI02,DC=cisco,DC=com") + ldapBaseProperties.SetBindMethod("Anonymous") + ldapBaseProperties.SetDomain("QATCSLABTPI02.cisco.com") + ldapBaseProperties.SetEnableEncryption(true) + ldapBaseProperties.SetEnableGroupAuthorization(true) + ldapBaseProperties.SetFilter("sAMAccountName") + ldapBaseProperties.SetGroupAttribute("memberOf") + ldapBaseProperties.SetNestedGroupSearchDepth(128) + ldapBaseProperties.SetTimeout(180) + return *ldapBaseProperties +} + +func setDnsProperties() intersight.IamLdapDnsParameters { + ldapDnsProperties := intersight.NewIamLdapDnsParametersWithDefaults() + ldapDnsProperties.SetSource("Extracted") + ldapDnsProperties.SetSearchForest("xyz") + ldapDnsProperties.SetSearchDomain("abc") + return *ldapDnsProperties +} + +func CreateLdapPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + baseProperties := setBaseProperties() + dnsProperties := setDnsProperties() + ldapPolicy := intersight.NewIamLdapPolicyWithDefaults() + ldapPolicy.SetName("tf_ldap1_sdk") + ldapPolicy.SetDescription("test policy") + ldapPolicy.SetEnabled(true) + ldapPolicy.SetEnableDns(true) + ldapPolicy.SetUserSearchPrecedence("LocalUserDb") + ldapPolicy.SetOrganization(organizationRelationship) + ldapPolicy.SetBaseProperties(baseProperties) + ldapPolicy.SetDnsParameters(dnsProperties) + resp, _, err := apiClient.IamApi.CreateIamLdapPolicy(ctx).IamLdapPolicy(*ldapPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/ipmiPolicy.md b/examples/policies/ipmiPolicy.md new file mode 100644 index 0000000000..ed718c8e6c --- /dev/null +++ b/examples/policies/ipmiPolicy.md @@ -0,0 +1,31 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + + +func CreateIpmiPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + ipmiPolicy := intersight.NewIpmioverlanPolicyWithDefaults() + ipmiPolicy.SetName("tf_ipmi_sdk") + ipmiPolicy.SetDescription("demo ipmi policy") + ipmiPolicy.SetEnabled(true) + ipmiPolicy.SetPrivilege("admin") + ipmiPolicy.SetOrganization(organizationRelationship) + resp, _, err := apiClient.IpmioverlanApi.CreateIpmioverlanPolicy(ctx).IpmioverlanPolicy(*ipmiPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/kvmPolicy.md b/examples/policies/kvmPolicy.md new file mode 100644 index 0000000000..b3b2c8e29a --- /dev/null +++ b/examples/policies/kvmPolicy.md @@ -0,0 +1,33 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateKvmPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + kvmPolicy := intersight.NewKvmPolicyWithDefaults() + kvmPolicy.SetName("tf_kvm_sdk") + kvmPolicy.SetDescription("demo kvm policy") + kvmPolicy.SetEnabled(true) + kvmPolicy.SetMaximumSessions(3) + kvmPolicy.SetRemotePort(2069) + kvmPolicy.SetEnableVideoEncryption(true) + kvmPolicy.SetEnableLocalServerVideo(true) + kvmPolicy.SetOrganization(organizationRelationship) + resp, _, err := apiClient.KvmApi.CreateKvmPolicy(ctx).KvmPolicy(*kvmPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/networkConfigPolicy.md b/examples/policies/networkConfigPolicy.md new file mode 100644 index 0000000000..8d1614a53d --- /dev/null +++ b/examples/policies/networkConfigPolicy.md @@ -0,0 +1,36 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateNetworkConfigPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + networkConfigPolicy := intersight.NewNetworkconfigPolicyWithDefaults() + networkConfigPolicy.SetName("tf_network_config1_sdk") + networkConfigPolicy.SetDescription("test policy") + networkConfigPolicy.SetEnableDynamicDns(false) + networkConfigPolicy.SetPreferredIpv6dnsServer("::") + networkConfigPolicy.SetEnableIpv6(true) + networkConfigPolicy.SetEnableIpv6dnsFromDhcp(false) + networkConfigPolicy.SetPreferredIpv4dnsServer("10.10.10.1") + networkConfigPolicy.SetAlternateIpv4dnsServer("10.10.10.1") + networkConfigPolicy.SetAlternateIpv6dnsServer("::") + networkConfigPolicy.SetEnableIpv4dnsFromDhcp(false) + networkConfigPolicy.SetOrganization(organizationRelationship) + resp, _, err := apiClient.NetworkconfigApi.CreateNetworkconfigPolicy(ctx).NetworkconfigPolicy(*networkConfigPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/ntpPolicy.md b/examples/policies/ntpPolicy.md new file mode 100644 index 0000000000..74064ecf0e --- /dev/null +++ b/examples/policies/ntpPolicy.md @@ -0,0 +1,36 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + + +func setServers() []string { + servers := []string{"ntp.esl.cisco.com", "time-a-g.nist.gov", "time-b-g.nist.gov"} + return servers +} + +func CreateNtpPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + ntpPolicy := intersight.NewNtpPolicyWithDefaults() + ntpPolicy.SetName("tf_ntp1_sdk") + ntpPolicy.SetEnabled(true) + ntpPolicy.SetOrganization(organizationRelationship) + servers := setServers() + ntpPolicy.SetNtpServers(servers) + resp, _, err := apiClient.NtpApi.CreateNtpPolicy(ctx).NtpPolicy(*ntpPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/policies.md b/examples/policies/policies.md new file mode 100644 index 0000000000..1b2a323064 --- /dev/null +++ b/examples/policies/policies.md @@ -0,0 +1,198 @@ +#### Example to create policy +``` +package policy + +import ( + "context" + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + + +type Config struct { + ApiKey string + SecretKey string + Endpoint string + ApiClient *intersight.APIClient + ctx context.Context +} + + +func ExecutePolicies(apiKey string, secret string, host string) { + + config := Config{ + ApiKey: apiKey, + SecretKey: secret, + Endpoint: host, + } + + adapterconfigPolicyRelationship := getPolicyRelationship("adapter.ConfigPolicy", config) + log.Printf("adapterconfigPolicy response: %v\n", adapterconfigPolicyRelationship) + + deviceconnectorPolicyRelationship := getPolicyRelationship("deviceconnector.Policy", config) + log.Printf("deviceconnector response: %v\n", deviceconnectorPolicyRelationship) + + ldapPolicyRelationship := getPolicyRelationship("iam.LdapPolicy", config) + log.Printf("ldapPolicy response: %v\n", ldapPolicyRelationship) + + ipmiPolicyRelationship := getPolicyRelationship("ipmioverlan.Policy", config) + log.Printf("ipmiPolicy response: %v\n", ipmiPolicyRelationship) + + kvmPolicyRelationship := getPolicyRelationship("kvm.Policy", config) + log.Printf("kvmPolicy response: %v\n", kvmPolicyRelationship) + + networkConfigPolicyRelationship := getPolicyRelationship("networkconfig.Policy", config) + log.Printf("networkConfigPolicy response: %v\n", networkConfigPolicyRelationship) + + ntpPolicyRelationship := getPolicyRelationship("ntp.Policy", config) + log.Printf("ntpPolicy response: %v\n", ntpPolicyRelationship) + + smtpPolicyRelationship := getPolicyRelationship("smtp.Policy", config) + log.Printf("smtpPolicy response: %v\n", smtpPolicyRelationship) + + snmpPolicyRelationship := getPolicyRelationship("snmp.Policy", config) + log.Printf("snmpPolicy response: %v\n", snmpPolicyRelationship) + + solPolicyRelationship := getPolicyRelationship("sol.Policy", config) + log.Printf("solPolicy response: %v\n", solPolicyRelationship) + + syslogPolicyRelationship := getPolicyRelationship("syslog.Policy", config) + log.Printf("syslogPolicy response: %v\n", syslogPolicyRelationship) + + userPolicyRelationship := getPolicyRelationship("iam.EndPointUserPolicy", config) + log.Printf("userPolicy response: %v\n", userPolicyRelationship) + + storagePolicyRelationship := getPolicyRelationship("storage.StoragePolicy", config) + log.Printf("storagePolicy response: %v\n", storagePolicyRelationship) + + storageDriveGroupRelationship := getPolicyRelationship("storage.DriveGroup", config) + log.Printf("storageDriveGroup response: %v\n", storageDriveGroupRelationship) + + vmediaPolicyRelationship := getPolicyRelationship("vmedia.Policy", config) + log.Printf("vmedia response: %v\n", vmediaPolicyRelationship) + + ethAdapterPolicyRelationship := getPolicyRelationship("vnic.EthAdapterPolicy", config) + log.Printf("ethAdapterPolicy response: %v\n", ethAdapterPolicyRelationship) + + ethNetworkPolicyRelationship := getPolicyRelationship("vnic.EthNetworkPolicy", config) + log.Printf("ethNetworkPolicy response: %v\n", ethNetworkPolicyRelationship) + + ethQosPolicyRelationship := getPolicyRelationship("vnic.EthQosPolicy", config) + log.Printf("ethQosPolicy response: %v\n", ethQosPolicyRelationship) + + lanPolicyRelationship := getPolicyRelationship("vnic.LanConnectivityPolicy", config) + log.Printf("lanPolicy response: %v\n", lanPolicyRelationship) + + ethIfPolicyRelationship := getPolicyRelationship("vnic.EthIf", config) + log.Printf("ethIfPolicy response: %v\n", ethIfPolicyRelationship) + + fcAdapterPolicyRelationship := getPolicyRelationship("vnic.FcAdapterPolicy", config) + log.Printf("fcAdapterPolicy response: %v\n", fcAdapterPolicyRelationship) + + fcNetworkPolicyRelationship := getPolicyRelationship("vnic.FcNetworkPolicy", config) + log.Printf("fcNetworkPolicy response: %v\n", fcNetworkPolicyRelationship) + + fcQosPolicyRelationship := getPolicyRelationship("vnic.FcQosPolicy", config) + log.Printf("fcQosPolicy response: %v\n", fcQosPolicyRelationship) + + sanPolicyRelationship := getPolicyRelationship("vnic.SanConnectivityPolicy", config) + log.Printf("sanPolicy response: %v\n", sanPolicyRelationship) + + fcIfPolicyRelationship := getPolicyRelationship("vnic.FcIf", config) + log.Printf("fcIfPolicy response: %v\n", fcIfPolicyRelationship) + + policies := []intersight.PolicyAbstractPolicyRelationship{*adapterconfigPolicyRelationship, *deviceconnectorPolicyRelationship, *ldapPolicyRelationship, *ipmiPolicyRelationship, *kvmPolicyRelationship, *networkConfigPolicyRelationship, *ntpPolicyRelationship, *smtpPolicyRelationship, *snmpPolicyRelationship, *solPolicyRelationship, *syslogPolicyRelationship, *userPolicyRelationship, *vmediaPolicyRelationship, *ethAdapterPolicyRelationship, *ethNetworkPolicyRelationship, *ethQosPolicyRelationship, *lanPolicyRelationship, *fcAdapterPolicyRelationship, *fcNetworkPolicyRelationship, *fcQosPolicyRelationship, *sanPolicyRelationship} + CreateServerProfile(&config, policies) +} + +func getOrganizationRelationship(moid string) intersight.OrganizationOrganizationRelationship { + organization := new(intersight.OrganizationOrganization) + organization.ClassId = "mo.MoRef" + organization.ObjectType = "organization.Organization" + organization.Moid = &moid + organizationRelationship := intersight.OrganizationOrganizationAsOrganizationOrganizationRelationship(organization) + return organizationRelationship +} + +func getDefaultOrgMoid(config *Config) string { + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + + org_resp, _, org_err := apiClient.OrganizationApi.GetOrganizationOrganizationList(ctx).Filter("Name eq 'default'").Execute() + if org_err != nil { + log.Fatal("Error: %v\n", org_err) + } + org_list := org_resp.OrganizationOrganizationList.GetResults() + if len(org_list) == 0 { + log.Fatal("Couldn't find the organization specified") + } + org_moid := org_list[0].MoBaseMo.GetMoid() + return org_moid +} + +func getPolicyRelationship(policy string, config Config) *intersight.PolicyAbstractPolicyRelationship { + var policy_moid string + switch policy { + case "adapter.ConfigPolicy": + policy_moid = CreateAdapterPolicy(&config) + case "deviceconnector.Policy": + policy_moid = CreateDeviceConnectorPolicy(&config) + case "iam.LdapPolicy": + policy_moid = CreateLdapPolicy(&config) + case "ipmioverlan.Policy": + policy_moid = CreateIpmiPolicy(&config) + case "kvm.Policy": + policy_moid = CreateKvmPolicy(&config) + case "networkconfig.Policy": + policy_moid = CreateNetworkConfigPolicy(&config) + case "ntp.Policy": + policy_moid = CreateNtpPolicy(&config) + case "smtp.Policy": + policy_moid = CreateSmtpPolicy(&config) + case "snmp.Policy": + policy_moid = CreateSnmpPolicy(&config) + case "sol.Policy": + policy_moid = CreateSolPolicy(&config) + case "syslog.Policy": + policy_moid = CreateSyslogPolicy(&config) + case "iam.EndPointUserPolicy": + policy_moid = CreateIamEndPointUserPolicy(&config) + case "storage.StoragePolicy": + policy_moid = CreateStorageStoragePolicy(&config) + case "storage.DriveGroup": + storageMoid := CreateStorageStoragePolicy(&config) + policy_moid = CreateSorageDriveGroup(&config,storageMoid) + case "vmedia.Policy": + policy_moid = CreateVmediaPolicy(&config) + case "vnic.EthAdapterPolicy": + policy_moid = CreateVnicEthAdapterPolicy(&config) + case "vnic.EthNetworkPolicy": + policy_moid = CreateVnicEthNetworkPolicy(&config) + case "vnic.EthQosPolicy": + policy_moid = CreateVnicEthQosPolicy(&config) + case "vnic.LanConnectivityPolicy": + policy_moid = CreateVnicLanConnectivityPolicy(&config) + case "vnic.EthIf": + policy_moid = CreateVnicEthIf(&config) + case "vnic.FcAdapterPolicy": + policy_moid = CreateVnicFcAdapterPolicy(&config) + case "vnic.FcNetworkPolicy": + policy_moid = CreateVnicFcNetworkPolicy(&config) + case "vnic.FcQosPolicy": + policy_moid = CreateVnicFcQosPolicy(&config) + case "vnic.SanConnectivityPolicy": + policy_moid = CreateVnicSanConnectivityPolicy(&config) + case "vnic.FcIf": + policy_moid = CreateVnicFcIf(&config) + } + + policy_object := new(intersight.PolicyAbstractPolicy) + policy_object.SetClassId("mo.MoRef") + policy_object.SetObjectType(policy) + policy_object.SetMoid(policy_moid) + policyRelationship := intersight.PolicyAbstractPolicyAsPolicyAbstractPolicyRelationship(policy_object) + return &policyRelationship +} +``` diff --git a/examples/policies/sdcardPolicy.md b/examples/policies/sdcardPolicy.md new file mode 100644 index 0000000000..f948d6d397 --- /dev/null +++ b/examples/policies/sdcardPolicy.md @@ -0,0 +1,48 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func createVirtualDrives() *intersight.SdcardVirtualDrive { + virtualDrives := intersight.NewSdcardVirtualDriveWithDefaults() + virtualDrives.SetEnable(true) + virtualDrives.SetObjectType("sdcard.OperatingSystem") + return virtualDrives +} + +func setPartitions() *intersight.SdcardPartition { + partitions := intersight.NewSdcardPartitionWithDefaults() + partitions.SetType("OS") + partitions.SetObjectType("sdcard.Partition") + virtualDrive := createVirtualDrives() + virtualDrives := []intersight.SdcardVirtualDrive{*virtualDrive} + partitions.SetVirtualDrives(virtualDrives) + return partitions +} + +func CreateSdCardPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + partition := setPartitions() + sdCardPolicy := intersight.NewSdcardPolicyWithDefaults() + sdCardPolicy.SetName("tf_sdcard_sdk") + sdCardPolicy.SetDescription("test policy") + sdCardPolicy.SetOrganization(organizationRelationship) + partitions := []intersight.SdcardPartition{*partition} + sdCardPolicy.SetPartitions(partitions) + resp, _, err := apiClient.SdcardApi.CreateSdcardPolicy(ctx).SdcardPolicy(*sdCardPolicy).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + return resp.GetMoid() +} +``` diff --git a/examples/policies/serverProfile.md b/examples/policies/serverProfile.md new file mode 100644 index 0000000000..fe21ea4d89 --- /dev/null +++ b/examples/policies/serverProfile.md @@ -0,0 +1,31 @@ +#### Example to create server profile by attaching the policies created +``` +package policy + +import ( + "log" + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateServerProfile(config *Config,policies []intersight.PolicyAbstractPolicyRelationship) { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + serverProfile := intersight.NewServerProfileWithDefaults() + serverProfile.ServerBaseProfile.PolicyAbstractConfigProfile.PolicyAbstractProfile.SetName("server_test") + serverProfile.ServerBaseProfile.PolicyAbstractConfigProfile.SetAction("No-op") + serverProfile.SetOrganization(organizationRelationship) + serverProfile.ServerBaseProfile.PolicyAbstractConfigProfile.SetPolicyBucket(policies) + + resp, _, err := apiClient.ServerApi.CreateServerProfile(ctx).ServerProfile(*serverProfile).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + log.Printf("Response: %v\n", resp) + log.Printf("Server profile created successfully.") +} + +``` diff --git a/examples/policies/smtpPolicy.md b/examples/policies/smtpPolicy.md new file mode 100644 index 0000000000..d7e9d57dd4 --- /dev/null +++ b/examples/policies/smtpPolicy.md @@ -0,0 +1,41 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateSmtpPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + smtpPolicy := intersight.NewSmtpPolicyWithDefaults() + smtpPolicy.PolicyAbstractPolicy.SetName("smtp_policy_test") + smtpPolicy.PolicyAbstractPolicy.SetDescription("sample testing smtp policy") + smtpPolicy.SetEnabled(false) + smtpPolicy.SetSmtpPort(int64(32)) + smtpPolicy.SetMinSeverity("critical") + smtpPolicy.SetSmtpServer("10.10.10.1") + smtpPolicy.SetSenderEmail("IMCSQAAutomation@cisco.com") + smtpRecipients := []string{"aw@cisco.com", + "cy@cisco.com", + "dz@cisco.com"} + smtpPolicy.SetSmtpRecipients(smtpRecipients) + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + smtpPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.SmtpApi.CreateSmtpPolicy(ctx).SmtpPolicy(*smtpPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/snmpPolicy.md b/examples/policies/snmpPolicy.md new file mode 100644 index 0000000000..a333780e8b --- /dev/null +++ b/examples/policies/snmpPolicy.md @@ -0,0 +1,69 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func createSnmpTrap() *intersight.SnmpTrap { + snmpTrap := intersight.NewSnmpTrap("snmp.Trap", "snmp.Trap") + snmpTrap.SetDestination("10.10.10.1") + snmpTrap.SetEnabled(false) + snmpTrap.SetPort(int64(660)) + snmpTrap.SetType("Trap") + snmpTrap.SetUser("demouser") + snmpTrap.SetVersion("V3") + return snmpTrap +} + +func createSnmpUser() *intersight.SnmpUser { + snmpUser := intersight.NewSnmpUser("snmp.User","snmp.User") + snmpUser.SetName("demouser") + snmpUser.SetPrivacyType("AES") + snmpUser.SetAuthPassword("changeMe") + snmpUser.SetPrivacyPassword("changeMe") + snmpUser.SetSecurityLevel("AuthPriv") + snmpUser.SetAuthType("SHA") + return snmpUser +} + +func CreateSnmpPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + snmpPolicy := intersight.NewSnmpPolicyWithDefaults() + snmpPolicy.PolicyAbstractPolicy.SetName("snmp_policy_test") + snmpPolicy.PolicyAbstractPolicy.SetDescription("sample testing snmp policy") + snmpPolicy.SetEnabled(true) + snmpPolicy.SetSnmpPort(int64(1983)) + snmpPolicy.SetAccessCommunityString("dummy123") + snmpPolicy.SetCommunityAccess("Disabled") + snmpPolicy.SetTrapCommunity("TrapCommunity") + snmpPolicy.SetSysContact("aanimish") + snmpPolicy.SetSysLocation("Karnataka") + snmpPolicy.SetEngineId("vvb") + snmpTrap1 := createSnmpTrap() + snmpTraps := []intersight.SnmpTrap{*snmpTrap1} + snmpPolicy.SetSnmpTraps(snmpTraps) + snmpUser1 := createSnmpUser() + snmpUsers := []intersight.SnmpUser{*snmpUser1} + snmpPolicy.SetSnmpUsers(snmpUsers) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + snmpPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.SnmpApi.CreateSnmpPolicy(ctx).SnmpPolicy(*snmpPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/solPolicy.md b/examples/policies/solPolicy.md new file mode 100644 index 0000000000..f6aa2d81b0 --- /dev/null +++ b/examples/policies/solPolicy.md @@ -0,0 +1,35 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateSolPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + solPolicy := intersight.NewSolPolicyWithDefaults() + solPolicy.PolicyAbstractPolicy.SetName("sol_test") + solPolicy.SetEnabled(false) + solPolicy.SetBaudRate(int32(9600)) + solPolicy.SetComPort("com1") + solPolicy.SetSshPort(int64(1096)) + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + solPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.SolApi.CreateSolPolicy(ctx).SolPolicy(*solPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid + } +``` diff --git a/examples/policies/syslogPolicy.md b/examples/policies/syslogPolicy.md new file mode 100644 index 0000000000..fa5b95a218 --- /dev/null +++ b/examples/policies/syslogPolicy.md @@ -0,0 +1,55 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateSyslogPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + syslogPolicy := intersight.NewSyslogPolicyWithDefaults() + syslogPolicy.PolicyAbstractPolicy.SetName("syslog_test") + syslogPolicy.PolicyAbstractPolicy.SetDescription("demo syslog policy") + + remoteClient1 := intersight.NewSyslogRemoteClientBaseWithDefaults() + remoteClient1.SetEnabled(true) + remoteClient1.SetHostname("10.10.10.10") + remoteClient1.SetPort(int64(514)) + remoteClient1.SetProtocol("tcp") + remoteClient1.SetMinSeverity("emergency") + + + remoteClient2 := intersight.NewSyslogRemoteClientBaseWithDefaults() + remoteClient2.SetEnabled(true) + remoteClient2.SetHostname("2001:0db8:0a0b:12f0:0000:0000:0000:0004") + remoteClient2.SetPort(int64(64000)) + remoteClient2.SetProtocol("udp") + remoteClient2.SetMinSeverity("emergency") + remoteClients := []intersight.SyslogRemoteClientBase{*remoteClient1, *remoteClient2} + syslogPolicy.SetRemoteClients(remoteClients) + + localClient1 := intersight.NewSyslogLocalClientBaseWithDefaults() + localClient1.SetMinSeverity("emergency") + localClients := []intersight.SyslogLocalClientBase{*localClient1} + syslogPolicy.SetLocalClients(localClients) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + syslogPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.SyslogApi.CreateSyslogPolicy(ctx).SyslogPolicy(*syslogPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/vmediaPolicy.md b/examples/policies/vmediaPolicy.md new file mode 100644 index 0000000000..1ddaa03f9a --- /dev/null +++ b/examples/policies/vmediaPolicy.md @@ -0,0 +1,36 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +func CreateVmediaPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + vmediaPolicy := intersight.NewVmediaPolicyWithDefaults() + vmediaPolicy.PolicyAbstractPolicy.SetName("vmedia_policy_test") + vmediaPolicy.PolicyAbstractPolicy.SetDescription("vmedia policy test") + vmediaPolicy.SetEnabled(true) + vmediaPolicy.SetEncryption(true) + vmediaPolicy.SetLowPowerUsb(true) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + vmediaPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + resp, _, err := apiClient.VmediaApi.CreateVmediaPolicy(ctx).VmediaPolicy(*vmediaPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := resp.GetMoid() + return moid +} +``` diff --git a/examples/policies/vnicEth.md b/examples/policies/vnicEth.md new file mode 100644 index 0000000000..fc34f3d911 --- /dev/null +++ b/examples/policies/vnicEth.md @@ -0,0 +1,269 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +var ethAdapterPolicyMoid, ethNetworkMoid, ethQosMoid, lanConnectivityMoid string + +func createEthAdapterPolicyRelationship(moid string) intersight.VnicEthAdapterPolicyRelationship { + adapterPolicy := new(intersight.VnicEthAdapterPolicy) + adapterPolicy.ClassId = "mo.MoRef" + adapterPolicy.ObjectType = "vnic.EthAdapterPolicy" + adapterPolicy.Moid = &moid + adapterRelationship := intersight.VnicEthAdapterPolicyAsVnicEthAdapterPolicyRelationship(adapterPolicy) + return adapterRelationship +} + +func createEthNetworkPolicyRelationship(moid string) intersight.VnicEthNetworkPolicyRelationship { + networkPolicy := new(intersight.VnicEthNetworkPolicy) + networkPolicy.ClassId = "mo.MoRef" + networkPolicy.ObjectType = "vnic.EthNetworkPolicy" + networkPolicy.Moid = &moid + networkRelationship := intersight.VnicEthNetworkPolicyAsVnicEthNetworkPolicyRelationship(networkPolicy) + return networkRelationship +} + +func createEthQosPolicyRelationship(moid string) intersight.VnicEthQosPolicyRelationship { + qosPolicy := new(intersight.VnicEthQosPolicy) + qosPolicy.ClassId = "mo.MoRef" + qosPolicy.ObjectType = "vnic.EthQosPolicy" + qosPolicy.Moid = &moid + qosRelationship := intersight.VnicEthQosPolicyAsVnicEthQosPolicyRelationship(qosPolicy) + return qosRelationship +} + +func createLanConnectivityPolicy(moid string) intersight.VnicLanConnectivityPolicyRelationship { + lanPolicy := new(intersight.VnicLanConnectivityPolicy) + lanPolicy.ClassId = "mo.MoRef" + lanPolicy.ObjectType = "vnic.LanConnectivityPolicy" + lanPolicy.Moid = &moid + lanRelationship := intersight.VnicLanConnectivityPolicyAsVnicLanConnectivityPolicyRelationship(lanPolicy) + return lanRelationship +} + +func CreateVnicEthAdapterPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + ethadapterPolicy := intersight.NewVnicEthAdapterPolicyWithDefaults() + ethadapterPolicy.PolicyAbstractPolicy.SetName("v_eth_adapter_test") + ethadapterPolicy.SetRssSettings(true) + ethadapterPolicy.SetUplinkFailbackTimeout(int64(5)) + + vxlanSettingsVal := intersight.NewVnicVxlanSettingsWithDefaults() + vxlanSettingsVal.SetEnabled(false) + vxlanSetting := intersight.NewNullableVnicVxlanSettings(vxlanSettingsVal) + vxlanSettings := vxlanSetting.Get() + ethadapterPolicy.SetVxlanSettings(*vxlanSettings) + + nvgreSettingsVal := intersight.NewVnicNvgreSettingsWithDefaults() + nvgreSettingsVal.SetEnabled(true) + nvgreSetting := intersight.NewNullableVnicNvgreSettings(nvgreSettingsVal) + nvgreSettings := nvgreSetting.Get() + ethadapterPolicy.SetNvgreSettings(*nvgreSettings) + + arfsSettingsVal := intersight.NewVnicArfsSettingsWithDefaults() + arfsSettingsVal.SetEnabled(true) + arfsSetting := intersight.NewNullableVnicArfsSettings(arfsSettingsVal) + arfsSettings := arfsSetting.Get() + ethadapterPolicy.SetArfsSettings(*arfsSettings) + + interruptSettingsVal := intersight.NewVnicEthInterruptSettingsWithDefaults() + interruptSettingsVal.SetCoalescingTime(int64(125)) + interruptSettingsVal.SetCoalescingType("MIN") + interruptSettingsVal.SetCount(int64(4)) + interruptSettingsVal.SetMode("MSI") + interruptSetting := intersight.NewNullableVnicEthInterruptSettings(interruptSettingsVal) + interruptSettings := interruptSetting.Get() + ethadapterPolicy.SetInterruptSettings(*interruptSettings) + + completionQueueSettingsVal := intersight.NewVnicCompletionQueueSettingsWithDefaults() + completionQueueSettingsVal.SetRingSize(int64(1)) + interruptSettingsVal.SetCount(int64(4)) + completionQueueSetting := intersight.NewNullableVnicCompletionQueueSettings(completionQueueSettingsVal) + completionQueueSettings := completionQueueSetting.Get() + ethadapterPolicy.SetCompletionQueueSettings(*completionQueueSettings) + + rxQueueSettingsVal := intersight.NewVnicEthRxQueueSettingsWithDefaults() + rxQueueSettingsVal.SetRingSize(int64(512)) + rxQueueSettingsVal.SetCount(int64(4)) + rxQueueSetting := intersight.NewNullableVnicEthRxQueueSettings(rxQueueSettingsVal) + rxQueueSettings := rxQueueSetting.Get() + ethadapterPolicy.SetRxQueueSettings(*rxQueueSettings) + + txQueueSettingsVal := intersight.NewVnicEthTxQueueSettingsWithDefaults() + txQueueSettingsVal.SetRingSize(int64(512)) + txQueueSettingsVal.SetCount(int64(4)) + txQueueSetting := intersight.NewNullableVnicEthTxQueueSettings(txQueueSettingsVal) + txQueueSettings := txQueueSetting.Get() + ethadapterPolicy.SetTxQueueSettings(*txQueueSettings) + + tcpOffloadSettingsVal := intersight.NewVnicTcpOffloadSettingsWithDefaults() + tcpOffloadSettingsVal.SetLargeReceive(true) + tcpOffloadSettingsVal.SetLargeSend(true) + tcpOffloadSettingsVal.SetRxChecksum(true) + tcpOffloadSettingsVal.SetTxChecksum(true) + tcpOffloadSetting := intersight.NewNullableVnicTcpOffloadSettings(tcpOffloadSettingsVal) + tcpOffloadSettings := tcpOffloadSetting.Get() + ethadapterPolicy.SetTcpOffloadSettings(*tcpOffloadSettings) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + ethadapterPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + respAdapter, _, err := apiClient.VnicApi.CreateVnicEthAdapterPolicy(ctx).VnicEthAdapterPolicy(*ethadapterPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + ethAdapterPolicyMoid = respAdapter.GetMoid() + return ethAdapterPolicyMoid +} + +func CreateVnicEthNetworkPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + ethNetworkPolicy := intersight.NewVnicEthNetworkPolicyWithDefaults() + ethNetworkPolicy.PolicyAbstractPolicy.SetName("v_eth_network_test") + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + ethNetworkPolicy.SetOrganization(organizationRelationship) + + vlanSettingsVal := intersight.NewVnicVlanSettingsWithDefaults() + vlanSettingsVal.SetDefaultVlan(int64(1)) + vlanSettingsVal.SetMode("ACCESS") + vlanSetting := intersight.NewNullableVnicVlanSettings(vlanSettingsVal) + vlanSettings := vlanSetting.Get() + ethNetworkPolicy.SetVlanSettings(*vlanSettings) + + ifMatch := "" + ifNoneMatch := "" + respNetwork, _, err := apiClient.VnicApi.CreateVnicEthNetworkPolicy(ctx).VnicEthNetworkPolicy(*ethNetworkPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + ethNetworkMoid = respNetwork.GetMoid() + return ethNetworkMoid +} + +func CreateVnicEthQosPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + ethQosPolicy := intersight.NewVnicEthQosPolicyWithDefaults() + ethQosPolicy.PolicyAbstractPolicy.SetName("v_eth_qos_test") + ethQosPolicy.SetMtu(int64(1500)) + ethQosPolicy.SetRateLimit(int64(0)) + ethQosPolicy.SetCos(int64(0)) + ethQosPolicy.SetTrustHostCos(false) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + ethQosPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + respQos, _, err := apiClient.VnicApi.CreateVnicEthQosPolicy(ctx).VnicEthQosPolicy(*ethQosPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + ethQosMoid = respQos.GetMoid() + return ethQosMoid +} + +func CreateVnicLanConnectivityPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + vniclanConnectivityPolicy := intersight.NewVnicLanConnectivityPolicyWithDefaults() + vniclanConnectivityPolicy.PolicyAbstractPolicy.SetName("vnic_lan_test") + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + vniclanConnectivityPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + respLan, _, err := apiClient.VnicApi.CreateVnicLanConnectivityPolicy(ctx).VnicLanConnectivityPolicy(*vniclanConnectivityPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + lanConnectivityMoid = respLan.GetMoid() + return lanConnectivityMoid +} + +func CreateVnicEthIf(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + ethIf := intersight.NewVnicEthIfWithDefaults() + ethIf.SetName("vnic_eth_if_test") + ethIf.SetOrder(int64(0)) + + placementSettingVal := intersight.NewVnicPlacementSettingsWithDefaults() + placementSettingVal.SetId("1") + placementSettingVal.SetPciLink(int64(0)) + placementSettingVal.SetUplink(int64(0)) + placementSetting := intersight.NewNullableVnicPlacementSettings(placementSettingVal) + placementSettings := placementSetting.Get() + ethIf.SetPlacement(*placementSettings) + + cdnVal := intersight.NewVnicCdnWithDefaults() + cdnVal.SetValue("VIC-1-eth00") + cdnVal.SetSource("user") + cdn := intersight.NewNullableVnicCdn(cdnVal) + cdn1 := cdn.Get() + ethIf.SetCdn(*cdn1) + + usnicSettingsVal := intersight.NewVnicUsnicSettingsWithDefaults() + usnicSettingsVal.SetCos(int64(5)) + usnicSettingsVal.SetCount(int64(0)) + usnicSetting := intersight.NewNullableVnicUsnicSettings(usnicSettingsVal) + usnicSettings := usnicSetting.Get() + ethIf.SetUsnicSettings(*usnicSettings) + + vmqSettingsVal := intersight.NewVnicVmqSettingsWithDefaults() + vmqSettingsVal.SetEnabled(true) + vmqSettingsVal.SetMultiQueueSupport(false) + vmqSettingsVal.SetNumInterrupts(int64(1)) + vmqSettingsVal.SetNumVmqs(int64(1)) + vmqSetting := intersight.NewNullableVnicVmqSettings(vmqSettingsVal) + vmqSettings := vmqSetting.Get() + ethIf.SetVmqSettings(*vmqSettings) + + ethAdapterPolicyRelationship := createEthAdapterPolicyRelationship(ethAdapterPolicyMoid) + ethIf.SetEthAdapterPolicy(ethAdapterPolicyRelationship) + + ethNetworkPolicyRelationship := createEthNetworkPolicyRelationship(ethNetworkMoid) + ethIf.SetEthNetworkPolicy(ethNetworkPolicyRelationship) + + ethQosPolicyRelationship := createEthQosPolicyRelationship(ethQosMoid) + ethIf.SetEthQosPolicy(ethQosPolicyRelationship) + + lanConnectivityPolicyRelationship := createLanConnectivityPolicy(lanConnectivityMoid) + ethIf.SetLanConnectivityPolicy(lanConnectivityPolicyRelationship) + + ifMatch := "" + ifNoneMatch := "" + ethIfResp, _, err := apiClient.VnicApi.CreateVnicEthIf(ctx).VnicEthIf(*ethIf).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := ethIfResp.GetMoid() + return moid +} + +``` diff --git a/examples/policies/vnicFc.md b/examples/policies/vnicFc.md new file mode 100644 index 0000000000..e15f79220e --- /dev/null +++ b/examples/policies/vnicFc.md @@ -0,0 +1,245 @@ +#### Example to create policy +``` +package policy + +import ( + "log" + + intersight "github.com/CiscoDevNet/intersight-go" +) + +var adapterPolicyMoid, fcNetworkMoid, qosMoid, sanConnectivityMoid string + +func createFcAdapterPolicyRelationship(moid string) intersight.VnicFcAdapterPolicyRelationship { + adapterPolicy := new(intersight.VnicFcAdapterPolicy) + adapterPolicy.ClassId = "mo.MoRef" + adapterPolicy.ObjectType = "vnic.FcAdapterPolicy" + adapterPolicy.Moid = &moid + adapterRelationship := intersight.VnicFcAdapterPolicyAsVnicFcAdapterPolicyRelationship(adapterPolicy) + return adapterRelationship +} + +func createFcNetworkPolicyRelationship(moid string) intersight.VnicFcNetworkPolicyRelationship { + networkPolicy := new(intersight.VnicFcNetworkPolicy) + networkPolicy.ClassId = "mo.MoRef" + networkPolicy.ObjectType = "vnic.FcNetworkPolicy" + networkPolicy.Moid = &moid + networkRelationship := intersight.VnicFcNetworkPolicyAsVnicFcNetworkPolicyRelationship(networkPolicy) + return networkRelationship +} + +func createFcQosPolicyRelationship(moid string) intersight.VnicFcQosPolicyRelationship { + qosPolicy := new(intersight.VnicFcQosPolicy) + qosPolicy.ClassId = "mo.MoRef" + qosPolicy.ObjectType = "vnic.FcQosPolicy" + qosPolicy.Moid = &moid + qosRelationship := intersight.VnicFcQosPolicyAsVnicFcQosPolicyRelationship(qosPolicy) + return qosRelationship +} + +func createSanConnectivityPolicy(moid string) intersight.VnicSanConnectivityPolicyRelationship { + sanPolicy := new(intersight.VnicSanConnectivityPolicy) + sanPolicy.ClassId = "mo.MoRef" + sanPolicy.ObjectType = "vnic.SanConnectivityPolicy" + sanPolicy.Moid = &moid + sanRelationship := intersight.VnicSanConnectivityPolicyAsVnicSanConnectivityPolicyRelationship(sanPolicy) + return sanRelationship +} + +func CreateVnicFcAdapterPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + fcAdapterPolicy := intersight.NewVnicFcAdapterPolicyWithDefaults() + fcAdapterPolicy.PolicyAbstractPolicy.SetName("fc_adapter_test") + fcAdapterPolicy.SetErrorDetectionTimeout(int64(100000)) + + errorRecoverySettingsVal := intersight.NewVnicFcErrorRecoverySettingsWithDefaults() + errorRecoverySettingsVal.SetEnabled(false) + errorRecoverySettingsVal.SetIoRetryCount(int64(255)) + errorRecoverySettingsVal.SetIoRetryTimeout(int64(50)) + errorRecoverySettingsVal.SetLinkDownTimeout(int64(240000)) + errorRecoverySettingsVal.SetPortDownTimeout(int64(240000)) + errorRecoverySetting := intersight.NewNullableVnicFcErrorRecoverySettings(errorRecoverySettingsVal) + errorRecoverySettings := errorRecoverySetting.Get() + fcAdapterPolicy.SetErrorRecoverySettings(*errorRecoverySettings) + + flogiSettingsVal := intersight.NewVnicFlogiSettingsWithDefaults() + flogiSettingsVal.SetRetries(int64(0)) + flogiSettingsVal.SetTimeout(int64(255000)) + flogiSetting := intersight.NewNullableVnicFlogiSettings(flogiSettingsVal) + flogiSettings := flogiSetting.Get() + fcAdapterPolicy.SetFlogiSettings(*flogiSettings) + + fcInterruptSettingsVal := intersight.NewVnicFcInterruptSettingsWithDefaults() + fcInterruptSettingsVal.SetMode("MSIx") + fcInterruptSetting := intersight.NewNullableVnicFcInterruptSettings(fcInterruptSettingsVal) + fcInterruptSettings := fcInterruptSetting.Get() + fcAdapterPolicy.SetInterruptSettings(*fcInterruptSettings) + + fcAdapterPolicy.SetIoThrottleCount(int64(1024)) + fcAdapterPolicy.SetLunCount(int64(1024)) + fcAdapterPolicy.SetLunQueueDepth(int64(254)) + + plogiSettingsVal := intersight.NewVnicPlogiSettingsWithDefaults() + plogiSettingsVal.SetRetries(int64(255)) + plogiSettingsVal.SetTimeout(int64(255000)) + plogiSetting := intersight.NewNullableVnicPlogiSettings(plogiSettingsVal) + plogiSettings := plogiSetting.Get() + fcAdapterPolicy.SetPlogiSettings(*plogiSettings) + + fcAdapterPolicy.SetResourceAllocationTimeout(int64(100000)) + + rxQueueSettingsVal := intersight.NewVnicFcQueueSettingsWithDefaults() + rxQueueSettingsVal.SetRingSize(int64(128)) + rxQueueSettingsVal.SetCount(int64(1)) + rxQueueSetting := intersight.NewNullableVnicFcQueueSettings(rxQueueSettingsVal) + rxQueueSettings := rxQueueSetting.Get() + fcAdapterPolicy.SetRxQueueSettings(*rxQueueSettings) + + txQueueSettingsVal := intersight.NewVnicFcQueueSettingsWithDefaults() + txQueueSettingsVal.SetRingSize(int64(128)) + txQueueSettingsVal.SetCount(int64(1)) + txQueueSetting := intersight.NewNullableVnicFcQueueSettings(txQueueSettingsVal) + txQueueSettings := txQueueSetting.Get() + fcAdapterPolicy.SetTxQueueSettings(*txQueueSettings) + + scsiQueueSettingsVal := intersight.NewVnicScsiQueueSettingsWithDefaults() + scsiQueueSettingsVal.SetRingSize(int64(152)) + scsiQueueSettingsVal.SetCount(int64(8)) + scsiQueueSetting := intersight.NewNullableVnicScsiQueueSettings(scsiQueueSettingsVal) + scsiQueueSettings := scsiQueueSetting.Get() + fcAdapterPolicy.SetScsiQueueSettings(*scsiQueueSettings) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + fcAdapterPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + adapterResp, _, err := apiClient.VnicApi.CreateVnicFcAdapterPolicy(ctx).VnicFcAdapterPolicy(*fcAdapterPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + adapterPolicyMoid = adapterResp.GetMoid() + return adapterPolicyMoid +} + +func CreateVnicFcNetworkPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + fcNetworkPolicy := intersight.NewVnicFcNetworkPolicyWithDefaults() + fcNetworkPolicy.PolicyAbstractPolicy.SetName("fc_network_test") + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + fcNetworkPolicy.SetOrganization(organizationRelationship) + + vsanSettingsVal := intersight.NewVnicVsanSettingsWithDefaults() + vsanSettingsVal.SetId(int64(100)) + vsanSetting := intersight.NewNullableVnicVsanSettings(vsanSettingsVal) + vsanSettings := vsanSetting.Get() + fcNetworkPolicy.SetVsanSettings(*vsanSettings) + + ifMatch := "" + ifNoneMatch := "" + networkResp, _, err := apiClient.VnicApi.CreateVnicFcNetworkPolicy(ctx).VnicFcNetworkPolicy(*fcNetworkPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + fcNetworkMoid = networkResp.GetMoid() + return fcNetworkMoid +} + +func CreateVnicFcQosPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + fcQosPolicy := intersight.NewVnicFcQosPolicyWithDefaults() + fcQosPolicy.PolicyAbstractPolicy.SetName("fc_qos_test") + fcQosPolicy.SetRateLimit(int64(10000)) + fcQosPolicy.SetCos(int64(6)) + fcQosPolicy.SetMaxDataFieldSize(int64(2112)) + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + fcQosPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + qosResp, _, err := apiClient.VnicApi.CreateVnicFcQosPolicy(ctx).VnicFcQosPolicy(*fcQosPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + qosMoid = qosResp.GetMoid() + return qosMoid +} + +func CreateVnicSanConnectivityPolicy(config *Config) string { + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + sanConnectivityPolicy := intersight.NewVnicSanConnectivityPolicyWithDefaults() + sanConnectivityPolicy.PolicyAbstractPolicy.SetName("vnic_san_test") + + org_moid := getDefaultOrgMoid(config) + organizationRelationship := getOrganizationRelationship(org_moid) + sanConnectivityPolicy.SetOrganization(organizationRelationship) + + ifMatch := "" + ifNoneMatch := "" + sanResp, _, err := apiClient.VnicApi.CreateVnicSanConnectivityPolicy(ctx).VnicSanConnectivityPolicy(*sanConnectivityPolicy).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + sanConnectivityMoid = sanResp.GetMoid() + return sanConnectivityMoid +} + +func CreateVnicFcIf(config *Config) string{ + var err error + cfg := getApiClient(config) + apiClient := cfg.ApiClient + ctx := cfg.ctx + fcIf := intersight.NewVnicFcIfWithDefaults() + fcIf.SetName("fc0") + fcIf.SetOrder(int64(1)) + + placementSettingVal := intersight.NewVnicPlacementSettingsWithDefaults() + placementSettingVal.SetId("1") + placementSettingVal.SetPciLink(int64(0)) + placementSettingVal.SetUplink(int64(0)) + placementSetting := intersight.NewNullableVnicPlacementSettings(placementSettingVal) + placementSettings := placementSetting.Get() + fcIf.SetPlacement(*placementSettings) + + fcIf.SetPersistentBindings(true) + + fcAdapterPolicyRelationship := createFcAdapterPolicyRelationship(adapterPolicyMoid) + fcIf.SetFcAdapterPolicy(fcAdapterPolicyRelationship) + + fcNetworkPolicyRelationship := createFcNetworkPolicyRelationship(fcNetworkMoid) + fcIf.SetFcNetworkPolicy(fcNetworkPolicyRelationship) + + fcQosPolicyRelationship := createFcQosPolicyRelationship(qosMoid) + fcIf.SetFcQosPolicy(fcQosPolicyRelationship) + + sanConnectivityPolicyRelationship := createSanConnectivityPolicy(sanConnectivityMoid) + fcIf.SetSanConnectivityPolicy(sanConnectivityPolicyRelationship) + + ifMatch := "" + ifNoneMatch := "" + fcIfResp, _, err := apiClient.VnicApi.CreateVnicFcIf(ctx).VnicFcIf(*fcIf).IfMatch(ifMatch).IfNoneMatch(ifNoneMatch).Execute() + if err != nil { + log.Fatalf("Error: %v\n", err) + } + moid := fcIfResp.GetMoid() + return moid +} + +```