How to use Read method of cdp Package

Best Rod code snippet using cdp.Read

types.go

Source:types.go Github

copy

Full Screen

...162 return ethutils.FromWei(ptoeWei, 27), nil163}164// GetEthPrice returns the price from the makerDAO oracle165func (client *Client) GetEthPrice() (eth *big.Float, err error) {166 result, err := client.oracle.Read(&bind.CallOpts{})167 if err != nil {168 return nil, errors.Wrap(err, "could not read the price from oracle")169 }170 wei := new(big.Int).SetBytes(result[:])171 eth = ethutils.FromWei(wei, 18)172 return eth, nil173}174// IsMkrAllowed returns true if the CDP Station contract is allowed to use our PETH175func (client *Client) IsMkrAllowed() (allowed bool, err error) {176 result, err := client.mkr.Allowance(&bind.CallOpts{}, client.address, client.dsproxyAddress)177 if err != nil {178 return false, errors.Wrap(err, "could not read the MKR status")179 }180 allowed = result.Cmp(ethutils.ToWei(big.NewFloat(1000000), 18)) > 0181 return allowed, nil182}183// IsDaiAllowed returns true if the CDP Station contract is allowed to use our DAI184func (client *Client) IsDaiAllowed() (allowed bool, err error) {185 result, err := client.dai.Allowance(&bind.CallOpts{}, client.address, client.dsproxyAddress)186 if err != nil {187 return false, errors.Wrap(err, "could not read the DAI status")188 }189 allowed = result.Cmp(ethutils.ToWei(big.NewFloat(1000000), 18)) > 0190 return allowed, nil191}192// DrawSellLock retrieve DAI from CDP, sells it on oasis.direct and locks ETH in the CDP193func (client Client) DrawSellLock(dai *big.Float) (*types.Transaction, error) {194 // allow 5% price slippage195 minLockDai := new(big.Float).Mul(dai, big.NewFloat(0.95))196 price, err := client.GetEthPrice()197 if err != nil {198 return nil, errors.Wrap(err, "could not retrieve ETH price")199 }200 minLock := new(big.Float).Quo(minLockDai, price)201 eth, err := client.GetOasisDaiToEth(dai)202 if err != nil {203 return nil, errors.Wrap(err, "could not get expected eth from exchange")204 }205 if eth.Cmp(minLock) < 0 {206 return nil, errors.New("price slippage to high")207 }208 auth, err := client.GetAuth()209 if err != nil {210 return nil, errors.Wrap(err, "could not get auth for transaction DrawSellLock")211 }212 a, err := abi.JSON(strings.NewReader(equalizer.EqualizerABI))213 if err != nil {214 return nil, errors.Wrap(err, "could not read equalizer ABI")215 }216 cdpIDb, err := ethutils.SliceToBytes32(big.NewInt(client.cdpID).Bytes())217 if err != nil {218 return nil, errors.Wrap(err, "could not get [32]byte")219 }220 b, err := a.Pack("drawSellLock", makerAddress, oasisAddress, cdpIDb, daiAddress, ethutils.ToWei(dai, 18), wethAddress, ethutils.ToWei(minLock, 18))221 if err != nil {222 return nil, errors.Wrapf(err, "could not pack data")223 }224 tx, err := client.dsproxy.Execute(auth, equalizerAddress, b)225 if err != nil {226 log.Fatal(err)227 return nil, errors.Wrapf(err, "could not DrawSellLock %.2f DAI in CDP #%d", dai, client.cdpID)228 }229 return tx, nil230}231// FreeSellWipe retrieve ETH from CDP, sells it on oasis.direct and wipe DAI in the CDP232func (client Client) FreeSellWipe(eth *big.Float) (*types.Transaction, error) {233 // allow 5% price slippage234 minWipeEth := new(big.Float).Mul(eth, big.NewFloat(0.95))235 price, err := client.GetEthPrice()236 if err != nil {237 return nil, errors.Wrap(err, "could not retrieve ETH price")238 }239 minWipe := new(big.Float).Mul(minWipeEth, price)240 dai, err := client.GetOasisEthToDai(eth)241 if err != nil {242 return nil, errors.Wrap(err, "could not get expected dai from exchange")243 }244 if dai.Cmp(minWipe) < 0 {245 return nil, errors.New("price slippage to high")246 }247 auth, err := client.GetAuth()248 if err != nil {249 return nil, errors.Wrap(err, "could not get auth for transaction FreeSellWipe")250 }251 a, err := abi.JSON(strings.NewReader(equalizer.EqualizerABI))252 if err != nil {253 return nil, errors.Wrapf(err, "could not read equalizer ABI")254 }255 cdpIDb, err := ethutils.SliceToBytes32(big.NewInt(client.cdpID).Bytes())256 if err != nil {257 return nil, errors.Wrapf(err, "could not get [32]byte")258 }259 b, err := a.Pack("freeSellWipe", makerAddress, oasisAddress, cdpIDb, daiAddress, ethutils.ToWei(eth, 18), wethAddress, ethutils.ToWei(minWipe, 18))260 if err != nil {261 return nil, errors.Wrapf(err, "could not pack data")262 }263 tx, err := client.dsproxy.Execute(auth, equalizerAddress, b)264 if err != nil {265 log.Fatal(err)266 return nil, errors.Wrapf(err, "could not freeSellWipe %.5f ETH in CDP #%d", eth, client.cdpID)267 }268 return tx, nil269}270// GetEthBalance returns the ETH balance of the account271func (client *Client) GetEthBalance() (eth *big.Float, err error) {272 wei, err := client.Client.BalanceAt(context.Background(), client.address, nil)273 if err != nil {274 return nil, errors.Wrapf(err, "could not read the ETH balance of `%s`", client.address.Hex())275 }276 return ethutils.FromWei(wei, 18), nil277}278// GetOasisDaiToEth returns the amount of ETH that will be given in exchange of DAI279func (client *Client) GetOasisDaiToEth(dai *big.Float) (eth *big.Float, err error) {280 ieth, err := client.oasis.GetBuyAmount(nil, wethAddress, daiAddress, ethutils.ToWei(dai, 18))281 if err != nil {282 return nil, errors.Wrapf(err, "could not read the ETH price when selling %.5f DAI to oasis", dai)283 }284 eth = ethutils.FromWei(ieth, 18)285 return eth, nil286}287// GetOasisEthToDai returns the amount of DAI that will be given in exchange of ETH288func (client *Client) GetOasisEthToDai(eth *big.Float) (dai *big.Float, err error) {289 idai, err := client.oasis.GetBuyAmount(nil, daiAddress, wethAddress, ethutils.ToWei(eth, 18))290 if err != nil {291 return nil, errors.Wrapf(err, "could not read the ETH price when selling %.5f ETH to oasis", eth)292 }293 dai = ethutils.FromWei(idai, 18)294 return dai, nil295}296// GetUniswapDaiToEth returns the amount of ETH that will be given in exchange of DAI297func (client *Client) GetUniswapDaiToEth(dai *big.Float) (eth *big.Float, err error) {298 ieth, err := client.uniswap.GetTokenToEthInputPrice(nil, ethutils.ToWei(dai, 18))299 if err != nil {300 return nil, errors.Wrapf(err, "could not read the ETH price when selling %.5f DAI to uniswap", dai)301 }302 eth = ethutils.FromWei(ieth, 18)303 return eth, nil304}305// GetUniswapEthToDai returns the amount of DAI that will be given in exchange of ETH306func (client *Client) GetUniswapEthToDai(eth *big.Float) (dai *big.Float, err error) {307 idai, err := client.uniswap.GetEthToTokenInputPrice(nil, ethutils.ToWei(eth, 18))308 if err != nil {309 return nil, errors.Wrapf(err, "could not read the ETH price when selling %.5f ETH to uniswap", eth)310 }311 dai = ethutils.FromWei(idai, 18)312 return dai, nil313}314// FreeEth unlock some ETH from the CDP315func (client *Client) FreeEth(eth *big.Float, cdp *cdp.CDP) (*types.Transaction, error) {316 auth, err := client.GetAuth()317 if err != nil {318 return nil, errors.Wrap(err, "could not generate the Auth")319 }320 a, err := abi.JSON(strings.NewReader(portal.PortalABI))321 if err != nil {322 return nil, errors.Wrapf(err, "could not read portal ABI")323 }324 cdpIDb, err := ethutils.SliceToBytes32(big.NewInt(client.cdpID).Bytes())325 if err != nil {326 return nil, errors.Wrapf(err, "could not get [32]byte")327 }328 b, err := a.Pack("free", makerAddress, cdpIDb, ethutils.ToWei(eth, 18))329 if err != nil {330 return nil, errors.Wrapf(err, "could not pack data")331 }332 tx, err := client.dsproxy.Execute(auth, portalAddress, b)333 if err != nil {334 log.Fatal(err)...

Full Screen

Full Screen

keeper_test.go

Source:keeper_test.go Github

copy

Full Screen

1package cdp2import (3 "fmt"4 "testing"5 sdk "github.com/cosmos/cosmos-sdk/types"6 "github.com/cosmos/cosmos-sdk/x/auth"7 "github.com/cosmos/cosmos-sdk/x/mock"8 "github.com/stretchr/testify/require"9 abci "github.com/tendermint/tendermint/abci/types"10)11// How could one reduce the number of params in the test cases. Create a table driven test for each of the 4 add/withdraw collateral/debt?12func TestKeeper_ModifyCDP(t *testing.T) {13 _, addrs := mock.GeneratePrivKeyAddressPairs(1)14 ownerAddr := addrs[0]15 type state struct { // TODO this allows invalid state to be set up, should it?16 CDP CDP17 OwnerCoins sdk.Coins18 GlobalDebt sdk.Int19 CollateralState CollateralState20 }21 type args struct {22 owner sdk.AccAddress23 collateralDenom string24 changeInCollateral sdk.Int25 changeInDebt sdk.Int26 }27 tests := []struct {28 name string29 priorState state30 price string31 // also missing CDPModuleParams32 args args33 expectPass bool34 expectedState state35 }{36 {37 "addCollateralAndDecreaseDebt",38 state{CDP{ownerAddr, "xrp", i(100), i(2)}, cs(c("xrp", 10), c(StableDenom, 2)), i(2), CollateralState{"xrp", i(2)}},39 "10.345",40 args{ownerAddr, "xrp", i(10), i(-1)},41 true,42 state{CDP{ownerAddr, "xrp", i(110), i(1)}, cs( /* 0xrp */ c(StableDenom, 1)), i(1), CollateralState{"xrp", i(1)}},43 },44 {45 "removeTooMuchCollateral",46 state{CDP{ownerAddr, "xrp", i(1000), i(200)}, cs(c("xrp", 10), c(StableDenom, 10)), i(200), CollateralState{"xrp", i(200)}},47 "1.00",48 args{ownerAddr, "xrp", i(-601), i(0)},49 false,50 state{CDP{ownerAddr, "xrp", i(1000), i(200)}, cs(c("xrp", 10), c(StableDenom, 10)), i(200), CollateralState{"xrp", i(200)}},51 },52 {53 "withdrawTooMuchStableCoin",54 state{CDP{ownerAddr, "xrp", i(1000), i(200)}, cs(c("xrp", 10), c(StableDenom, 10)), i(200), CollateralState{"xrp", i(200)}},55 "1.00",56 args{ownerAddr, "xrp", i(0), i(301)},57 false,58 state{CDP{ownerAddr, "xrp", i(1000), i(200)}, cs(c("xrp", 10), c(StableDenom, 10)), i(200), CollateralState{"xrp", i(200)}},59 },60 {61 "createCDPAndWithdrawStable",62 state{CDP{}, cs(c("xrp", 10), c(StableDenom, 10)), i(0), CollateralState{"xrp", i(0)}},63 "1.00",64 args{ownerAddr, "xrp", i(5), i(2)},65 true,66 state{CDP{ownerAddr, "xrp", i(5), i(2)}, cs(c("xrp", 5), c(StableDenom, 12)), i(2), CollateralState{"xrp", i(2)}},67 },68 {69 "emptyCDP",70 state{CDP{ownerAddr, "xrp", i(1000), i(200)}, cs(c("xrp", 10), c(StableDenom, 201)), i(200), CollateralState{"xrp", i(200)}},71 "1.00",72 args{ownerAddr, "xrp", i(-1000), i(-200)},73 true,74 state{CDP{}, cs(c("xrp", 1010), c(StableDenom, 1)), i(0), CollateralState{"xrp", i(0)}},75 },76 {77 "invalidCollateralType",78 state{CDP{}, cs(c("shitcoin", 5000000)), i(0), CollateralState{}},79 "0.000001",80 args{ownerAddr, "shitcoin", i(5000000), i(1)}, // ratio of 5:181 false,82 state{CDP{}, cs(c("shitcoin", 5000000)), i(0), CollateralState{}},83 },84 }85 for _, tc := range tests {86 t.Run(tc.name, func(t *testing.T) {87 // setup keeper88 mapp, keeper := setUpMockAppWithoutGenesis()89 // initialize cdp owner account with coins90 genAcc := auth.BaseAccount{91 Address: ownerAddr,92 Coins: tc.priorState.OwnerCoins,93 }94 mock.SetGenesis(mapp, []auth.Account{&genAcc})95 // create a new context96 header := abci.Header{Height: mapp.LastBlockHeight() + 1}97 mapp.BeginBlock(abci.RequestBeginBlock{Header: header})98 ctx := mapp.BaseApp.NewContext(false, header)99 // setup store state100 keeper.pricefeed.AddAsset(ctx, "xrp", "xrp test")101 keeper.pricefeed.SetPrice(102 ctx, sdk.AccAddress{}, "xrp",103 sdk.MustNewDecFromStr(tc.price),104 i(10))105 keeper.pricefeed.SetCurrentPrices(ctx)106 if tc.priorState.CDP.CollateralDenom != "" { // check if the prior CDP should be created or not (see if an empty one was specified)107 keeper.setCDP(ctx, tc.priorState.CDP)108 }109 keeper.setGlobalDebt(ctx, tc.priorState.GlobalDebt)110 if tc.priorState.CollateralState.Denom != "" {111 keeper.setCollateralState(ctx, tc.priorState.CollateralState)112 }113 // call func under test114 err := keeper.ModifyCDP(ctx, tc.args.owner, tc.args.collateralDenom, tc.args.changeInCollateral, tc.args.changeInDebt)115 mapp.EndBlock(abci.RequestEndBlock{})116 mapp.Commit()117 // check for err118 if tc.expectPass {119 require.NoError(t, err, fmt.Sprint(err))120 } else {121 require.Error(t, err)122 }123 // get new state for verification124 actualCDP, found := keeper.GetCDP(ctx, tc.args.owner, tc.args.collateralDenom)125 actualGDebt := keeper.GetGlobalDebt(ctx)126 actualCstate, _ := keeper.GetCollateralState(ctx, tc.args.collateralDenom)127 // check state128 require.Equal(t, tc.expectedState.CDP, actualCDP)129 if tc.expectedState.CDP.CollateralDenom == "" { // if the expected CDP is blank, then expect the CDP to have been deleted (hence not found)130 require.False(t, found)131 } else {132 require.True(t, found)133 }134 require.Equal(t, tc.expectedState.GlobalDebt, actualGDebt)135 require.Equal(t, tc.expectedState.CollateralState, actualCstate)136 // check owner balance137 mock.CheckBalance(t, mapp, ownerAddr, tc.expectedState.OwnerCoins)138 })139 }140}141// TODO change to table driven test to test more test cases142func TestKeeper_PartialSeizeCDP(t *testing.T) {143 // Setup144 const collateral = "xrp"145 mapp, keeper := setUpMockAppWithoutGenesis()146 genAccs, addrs, _, _ := mock.CreateGenAccounts(1, cs(c(collateral, 100)))147 testAddr := addrs[0]148 mock.SetGenesis(mapp, genAccs)149 // setup pricefeed150 header := abci.Header{Height: mapp.LastBlockHeight() + 1}151 mapp.BeginBlock(abci.RequestBeginBlock{Header: header})152 ctx := mapp.BaseApp.NewContext(false, header)153 keeper.pricefeed.AddAsset(ctx, collateral, "test description")154 keeper.pricefeed.SetPrice(155 ctx, sdk.AccAddress{}, collateral,156 sdk.MustNewDecFromStr("1.00"),157 i(10))158 keeper.pricefeed.SetCurrentPrices(ctx)159 // Create CDP160 err := keeper.ModifyCDP(ctx, testAddr, collateral, i(10), i(5))161 require.NoError(t, err)162 // Reduce price163 keeper.pricefeed.SetPrice(164 ctx, sdk.AccAddress{}, collateral,165 sdk.MustNewDecFromStr("0.90"),166 i(10))167 keeper.pricefeed.SetCurrentPrices(ctx)168 // Seize entire CDP169 err = keeper.PartialSeizeCDP(ctx, testAddr, collateral, i(10), i(5))170 // Check171 require.NoError(t, err)172 _, found := keeper.GetCDP(ctx, testAddr, collateral)173 require.False(t, found)174 collateralState, found := keeper.GetCollateralState(ctx, collateral)175 require.True(t, found)176 require.Equal(t, sdk.ZeroInt(), collateralState.TotalDebt)177}178func TestKeeper_GetCDPs(t *testing.T) {179 // setup keeper180 mapp, keeper := setUpMockAppWithoutGenesis()181 mock.SetGenesis(mapp, []auth.Account(nil))182 header := abci.Header{Height: mapp.LastBlockHeight() + 1}183 mapp.BeginBlock(abci.RequestBeginBlock{Header: header})184 ctx := mapp.BaseApp.NewContext(false, header)185 // setup CDPs186 _, addrs := mock.GeneratePrivKeyAddressPairs(2)187 cdps := CDPs{188 {addrs[0], "xrp", i(4000), i(5)},189 {addrs[1], "xrp", i(4000), i(2000)},190 {addrs[0], "btc", i(10), i(20)},191 }192 for _, cdp := range cdps {193 keeper.setCDP(ctx, cdp)194 }195 // Check nil params returns all CDPs196 returnedCdps, err := keeper.GetCDPs(ctx, "", sdk.Dec{})197 require.NoError(t, err)198 require.Equal(t,199 CDPs{200 {addrs[0], "btc", i(10), i(20)},201 {addrs[1], "xrp", i(4000), i(2000)},202 {addrs[0], "xrp", i(4000), i(5)}},203 returnedCdps,204 )205 // Check correct CDPs filtered by collateral and sorted206 returnedCdps, err = keeper.GetCDPs(ctx, "xrp", d("0.00000001"))207 require.NoError(t, err)208 require.Equal(t,209 CDPs{210 {addrs[1], "xrp", i(4000), i(2000)},211 {addrs[0], "xrp", i(4000), i(5)}},212 returnedCdps,213 )214 returnedCdps, err = keeper.GetCDPs(ctx, "xrp", sdk.Dec{})215 require.NoError(t, err)216 require.Equal(t,217 CDPs{218 {addrs[1], "xrp", i(4000), i(2000)},219 {addrs[0], "xrp", i(4000), i(5)}},220 returnedCdps,221 )222 returnedCdps, err = keeper.GetCDPs(ctx, "xrp", d("0.9"))223 require.NoError(t, err)224 require.Equal(t,225 CDPs{226 {addrs[1], "xrp", i(4000), i(2000)}},227 returnedCdps,228 )229 // Check high price returns no CDPs230 returnedCdps, err = keeper.GetCDPs(ctx, "xrp", d("999999999.99"))231 require.NoError(t, err)232 require.Equal(t,233 CDPs(nil),234 returnedCdps,235 )236 // Check unauthorized collateral denom returns error237 _, err = keeper.GetCDPs(ctx, "a non existent coin", d("0.34023"))238 require.Error(t, err)239 // Check price without collateral returns error240 _, err = keeper.GetCDPs(ctx, "", d("0.34023"))241 require.Error(t, err)242 // Check deleting a CDP removes it243 keeper.deleteCDP(ctx, cdps[0])244 returnedCdps, err = keeper.GetCDPs(ctx, "", sdk.Dec{})245 require.NoError(t, err)246 require.Equal(t,247 CDPs{248 {addrs[0], "btc", i(10), i(20)},249 {addrs[1], "xrp", i(4000), i(2000)}},250 returnedCdps,251 )252}253func TestKeeper_GetSetDeleteCDP(t *testing.T) {254 // setup keeper, create CDP255 mapp, keeper := setUpMockAppWithoutGenesis()256 header := abci.Header{Height: mapp.LastBlockHeight() + 1}257 mapp.BeginBlock(abci.RequestBeginBlock{Header: header})258 ctx := mapp.BaseApp.NewContext(false, header)259 _, addrs := mock.GeneratePrivKeyAddressPairs(1)260 cdp := CDP{addrs[0], "xrp", i(412), i(56)}261 // write and read from store262 keeper.setCDP(ctx, cdp)263 readCDP, found := keeper.GetCDP(ctx, cdp.Owner, cdp.CollateralDenom)264 // check before and after match265 require.True(t, found)266 require.Equal(t, cdp, readCDP)267 // delete auction268 keeper.deleteCDP(ctx, cdp)269 // check auction does not exist270 _, found = keeper.GetCDP(ctx, cdp.Owner, cdp.CollateralDenom)271 require.False(t, found)272}273func TestKeeper_GetSetGDebt(t *testing.T) {274 // setup keeper, create GDebt275 mapp, keeper := setUpMockAppWithoutGenesis()276 header := abci.Header{Height: mapp.LastBlockHeight() + 1}277 mapp.BeginBlock(abci.RequestBeginBlock{Header: header})278 ctx := mapp.BaseApp.NewContext(false, header)279 gDebt := i(4120000)280 // write and read from store281 keeper.setGlobalDebt(ctx, gDebt)282 readGDebt := keeper.GetGlobalDebt(ctx)283 // check before and after match284 require.Equal(t, gDebt, readGDebt)285}286func TestKeeper_GetSetCollateralState(t *testing.T) {287 // setup keeper, create CState288 mapp, keeper := setUpMockAppWithoutGenesis()289 header := abci.Header{Height: mapp.LastBlockHeight() + 1}290 mapp.BeginBlock(abci.RequestBeginBlock{Header: header})291 ctx := mapp.BaseApp.NewContext(false, header)292 collateralState := CollateralState{"xrp", i(15400)}293 // write and read from store294 keeper.setCollateralState(ctx, collateralState)295 readCState, found := keeper.GetCollateralState(ctx, collateralState.Denom)296 // check before and after match297 require.Equal(t, collateralState, readCState)298 require.True(t, found)299}...

Full Screen

Full Screen

resource_aci_cdpifpol.go

Source:resource_aci_cdpifpol.go Github

copy

Full Screen

...12func resourceAciCDPInterfacePolicy() *schema.Resource {13 return &schema.Resource{14 CreateContext: resourceAciCDPInterfacePolicyCreate,15 UpdateContext: resourceAciCDPInterfacePolicyUpdate,16 ReadContext: resourceAciCDPInterfacePolicyRead,17 DeleteContext: resourceAciCDPInterfacePolicyDelete,18 Importer: &schema.ResourceImporter{19 State: resourceAciCDPInterfacePolicyImport,20 },21 SchemaVersion: 1,22 Schema: AppendBaseAttrSchema(map[string]*schema.Schema{23 "name": &schema.Schema{24 Type: schema.TypeString,25 Required: true,26 ForceNew: true,27 },28 "admin_st": &schema.Schema{29 Type: schema.TypeString,30 Optional: true,31 Computed: true,32 ValidateFunc: validation.StringInSlice([]string{33 "enabled",34 "disabled",35 }, false),36 },37 "name_alias": &schema.Schema{38 Type: schema.TypeString,39 Optional: true,40 Computed: true,41 },42 }),43 }44}45func getRemoteCDPInterfacePolicy(client *client.Client, dn string) (*models.CDPInterfacePolicy, error) {46 cdpIfPolCont, err := client.Get(dn)47 if err != nil {48 return nil, err49 }50 cdpIfPol := models.CDPInterfacePolicyFromContainer(cdpIfPolCont)51 if cdpIfPol.DistinguishedName == "" {52 return nil, fmt.Errorf("CDPInterfacePolicy %s not found", cdpIfPol.DistinguishedName)53 }54 return cdpIfPol, nil55}56func setCDPInterfacePolicyAttributes(cdpIfPol *models.CDPInterfacePolicy, d *schema.ResourceData) (*schema.ResourceData, error) {57 d.SetId(cdpIfPol.DistinguishedName)58 d.Set("description", cdpIfPol.Description)59 cdpIfPolMap, err := cdpIfPol.ToMap()60 if err != nil {61 return d, err62 }63 d.Set("name", cdpIfPolMap["name"])64 d.Set("admin_st", cdpIfPolMap["adminSt"])65 d.Set("annotation", cdpIfPolMap["annotation"])66 d.Set("name_alias", cdpIfPolMap["nameAlias"])67 return d, nil68}69func resourceAciCDPInterfacePolicyImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {70 log.Printf("[DEBUG] %s: Beginning Import", d.Id())71 aciClient := m.(*client.Client)72 dn := d.Id()73 cdpIfPol, err := getRemoteCDPInterfacePolicy(aciClient, dn)74 if err != nil {75 return nil, err76 }77 schemaFilled, err := setCDPInterfacePolicyAttributes(cdpIfPol, d)78 if err != nil {79 return nil, err80 }81 log.Printf("[DEBUG] %s: Import finished successfully", d.Id())82 return []*schema.ResourceData{schemaFilled}, nil83}84func resourceAciCDPInterfacePolicyCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {85 log.Printf("[DEBUG] CDPInterfacePolicy: Beginning Creation")86 aciClient := m.(*client.Client)87 desc := d.Get("description").(string)88 name := d.Get("name").(string)89 cdpIfPolAttr := models.CDPInterfacePolicyAttributes{}90 if AdminSt, ok := d.GetOk("admin_st"); ok {91 cdpIfPolAttr.AdminSt = AdminSt.(string)92 }93 if Annotation, ok := d.GetOk("annotation"); ok {94 cdpIfPolAttr.Annotation = Annotation.(string)95 } else {96 cdpIfPolAttr.Annotation = "{}"97 }98 if NameAlias, ok := d.GetOk("name_alias"); ok {99 cdpIfPolAttr.NameAlias = NameAlias.(string)100 }101 cdpIfPol := models.NewCDPInterfacePolicy(fmt.Sprintf("infra/cdpIfP-%s", name), "uni", desc, cdpIfPolAttr)102 err := aciClient.Save(cdpIfPol)103 if err != nil {104 return diag.FromErr(err)105 }106 d.SetId(cdpIfPol.DistinguishedName)107 log.Printf("[DEBUG] %s: Creation finished successfully", d.Id())108 return resourceAciCDPInterfacePolicyRead(ctx, d, m)109}110func resourceAciCDPInterfacePolicyUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {111 log.Printf("[DEBUG] CDPInterfacePolicy: Beginning Update")112 aciClient := m.(*client.Client)113 desc := d.Get("description").(string)114 name := d.Get("name").(string)115 cdpIfPolAttr := models.CDPInterfacePolicyAttributes{}116 if AdminSt, ok := d.GetOk("admin_st"); ok {117 cdpIfPolAttr.AdminSt = AdminSt.(string)118 }119 if Annotation, ok := d.GetOk("annotation"); ok {120 cdpIfPolAttr.Annotation = Annotation.(string)121 } else {122 cdpIfPolAttr.Annotation = "{}"123 }124 if NameAlias, ok := d.GetOk("name_alias"); ok {125 cdpIfPolAttr.NameAlias = NameAlias.(string)126 }127 cdpIfPol := models.NewCDPInterfacePolicy(fmt.Sprintf("infra/cdpIfP-%s", name), "uni", desc, cdpIfPolAttr)128 cdpIfPol.Status = "modified"129 err := aciClient.Save(cdpIfPol)130 if err != nil {131 return diag.FromErr(err)132 }133 d.SetId(cdpIfPol.DistinguishedName)134 log.Printf("[DEBUG] %s: Update finished successfully", d.Id())135 return resourceAciCDPInterfacePolicyRead(ctx, d, m)136}137func resourceAciCDPInterfacePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {138 log.Printf("[DEBUG] %s: Beginning Read", d.Id())139 aciClient := m.(*client.Client)140 dn := d.Id()141 cdpIfPol, err := getRemoteCDPInterfacePolicy(aciClient, dn)142 if err != nil {143 d.SetId("")144 return nil145 }146 _, err = setCDPInterfacePolicyAttributes(cdpIfPol, d)147 if err != nil {148 d.SetId("")149 return nil150 }151 log.Printf("[DEBUG] %s: Read finished successfully", d.Id())152 return nil153}154func resourceAciCDPInterfacePolicyDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {155 log.Printf("[DEBUG] %s: Beginning Destroy", d.Id())156 aciClient := m.(*client.Client)157 dn := d.Id()158 err := aciClient.DeleteByDn(dn, "cdpIfPol")159 if err != nil {160 return diag.FromErr(err)161 }162 log.Printf("[DEBUG] %s: Destroy finished successfully", d.Id())163 d.SetId("")164 return diag.FromErr(err)165}...

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1func main() {2 cdp := NewCDP()3 cdp.Read()4}5func main() {6 cdp := NewCDP()7 cdp.Read()8}9func main() {10 cdp := NewCDP()11 cdp.Read()12}13func main() {14 cdp := NewCDP()15 cdp.Read()16}17func main() {18 cdp := NewCDP()19 cdp.Read()20}21func main() {22 cdp := NewCDP()23 cdp.Read()24}25func main() {26 cdp := NewCDP()27 cdp.Read()28}29func main() {30 cdp := NewCDP()31 cdp.Read()32}33func main() {34 cdp := NewCDP()35 cdp.Read()36}37func main() {38 cdp := NewCDP()39 cdp.Read()40}41func main() {42 cdp := NewCDP()43 cdp.Read()44}45func main() {46 cdp := NewCDP()47 cdp.Read()48}49func main() {50 cdp := NewCDP()51 cdp.Read()52}53func main() {54 cdp := NewCDP()55 cdp.Read()56}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1func main() {2 cdp := &CDP{Player: &Player{}}3 cdp.Play()4}5func main() {6 cdp := &CDP{Player: &Player{}}7 cdp.Play()8}9func main() {10 cdp := &CDP{Player: &Player{}}11 cdp.Play()12}13func main() {14 cdp := &CDP{Player: &Player{}}15 cdp.Play()16}17func main() {18 cdp := &CDP{Player: &Player{}}19 cdp.Play()20}21func main() {22 cdp := &CDP{Player: &Player{}}23 cdp.Play()24}25func main() {26 cdp := &CDP{Player: &Player{}}27 cdp.Play()28}29func main() {30 cdp := &CDP{Player: &Player{}}31 cdp.Play()32}33func main() {34 cdp := &CDP{Player: &Player{}}35 cdp.Play()36}37func main() {38 cdp := &CDP{Player: &Player{}}39 cdp.Play()40}41func main() {42 cdp := &CDP{Player: &Player{}}43 cdp.Play()44}45func main() {46 cdp := &CDP{Player: &Player{}}47 cdp.Play()48}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3file, err := os.Open("cdp.txt")4if err != nil {5fmt.Println(err)6}7scanner := bufio.NewScanner(file)8for scanner.Scan() {9cdp1.Read(scanner.Text())10}11file.Close()12cdp1.Print()13}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 cdp1 := cdp.NewCdp()5 cdp1.Read()6}7import (8func main() {9 fmt.Println("Hello, playground")10 cdp1 := cdp.NewCdp()11 cdp1.Read()12}13import (14func main() {15 fmt.Println("Hello, playground")16 cdp1 := cdp.NewCdp()17 cdp1.Read()18}19import (20func main() {21 fmt.Println("Hello, playground")22 cdp1 := cdp.NewCdp()23 cdp1.Read()24}25import (26func main() {27 fmt.Println("Hello, playground")28 cdp1 := cdp.NewCdp()29 cdp1.Read()30}31import (32func main() {33 fmt.Println("Hello, playground")34 cdp1 := cdp.NewCdp()35 cdp1.Read()36}37import (38func main() {39 fmt.Println("Hello, playground")40 cdp1 := cdp.NewCdp()41 cdp1.Read()42}43import (

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := cdp.New()4 fmt.Println(c)5}6ReadAll() method of cdp class7func (c *cdp) ReadAll(url string) map[string]string8import (9func main() {10 c := cdp.New()11 fmt.Println(c)12}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful