ONTAP Rest API Discussions

PCL REST API : How to create cifs share

ogatat
1,082 Views

I redad https://library.netapp.com/ecmdocs/ECMLP2874673/html/resources/cifs_share.html and according to sample, I tired to creae cifs sahre as bellow:

--

resource=CifsShare()
resource.name="vol1"
resource.path="/vol1"
resource.svm.uuid="47604f0f-59a4-11ec-be69-00a0985c5d5b"
resource.post(hydrate=True)

--

Error:

AttributeError: The 'svm' field has not been set on the CifsShare. Try refreshing the object by calling get().

 

I treied with "key":"values" but failed.. How is correct way setting "svm.uuid"?

1 ACCEPTED SOLUTION

RobertBlackhart
1,058 Views

The docs are a little misleading here. Newer versions of the docs will address this issue.

 

Since svm is an object, you can't access its fields before it is created. There are two ways you could change your code. Here's the simplest one:

 

resource=CifsShare()
resource.name="vol1"
resource.path="/vol1"
resource.svm={"uuid": "47604f0f-59a4-11ec-be69-00a0985c5d5b"}
resource.post(hydrate=True)

Only slightly more complicated, this will also work:

from netapp_ontap.resources import Svm

resource=CifsShare()
resource.name="vol1"
resource.path="/vol1"
resource.svm=Svm(uuid="47604f0f-59a4-11ec-be69-00a0985c5d5b")
resource.post(hydrate=True)

In the second example, I imported the Svm object so that I can construct it. In the first, I just used the dictionary representation so no imports needed. Both will send equal requests and behave the same afterwards.

View solution in original post

4 REPLIES 4

pedro_rocha
1,073 Views

Are you using all the parameters as in the example?

 

Did you set resource.svm.name?

ogatat
1,065 Views

According to exmaple, following is the all parameters but the result is the same as before.

 

---

from netapp_ontap import HostConnection
from netapp_ontap.resources import Svm, CifsShare
with HostConnection("10.x.x.x", username="admin", password="xxxxxxx", verify=False):
resource=CifsShare()
resource.name="vol1"
resource.path="/vol1"
resource.svm.uuid="47604f0f-59a4-11ec-be69-00a0985c5d5b"
resource.svm.uuid="demo"
resource.access_based_enumeration = False
resource.acls = [
{"permission": "no_access", "type": "unix_user", "user_or_group": "root"}
]
resource.change_notify = True
resource.comment = "vol1"
resource.encryption = False
resource.home_directory = False
resource.oplocks = True
resource.unix_symlink = "local"
resource.post(hydrate=True)

 

RobertBlackhart
1,059 Views

The docs are a little misleading here. Newer versions of the docs will address this issue.

 

Since svm is an object, you can't access its fields before it is created. There are two ways you could change your code. Here's the simplest one:

 

resource=CifsShare()
resource.name="vol1"
resource.path="/vol1"
resource.svm={"uuid": "47604f0f-59a4-11ec-be69-00a0985c5d5b"}
resource.post(hydrate=True)

Only slightly more complicated, this will also work:

from netapp_ontap.resources import Svm

resource=CifsShare()
resource.name="vol1"
resource.path="/vol1"
resource.svm=Svm(uuid="47604f0f-59a4-11ec-be69-00a0985c5d5b")
resource.post(hydrate=True)

In the second example, I imported the Svm object so that I can construct it. In the first, I just used the dictionary representation so no imports needed. Both will send equal requests and behave the same afterwards.

ogatat
1,052 Views

Both codes successfullly worked with "name" though documentation says "or" as bellow:

  • svm.uuid or svm.name - Existing SVM in which to create the CIFS share.

 

#failed: uuid only
resource.svm={"uuid": "47604f0f-59a4-11ec-be69-00a0985c5d5b"}

#Success: name only
resource.svm={"name": "demo"}

#Success: name and uuid
resource.svm={"uuid": "47604f0f-59a4-11ec-be69-00a0985c5d5b"}
resource.svm={"name": "demo")

 

 

Public