ONTAP Rest API Discussions

ONTAP CIFS service delete with Python client library 9.7

badrian
2,436 Views

I am going crazy. Can anybody tell me the secret of deleting a CIFS server with Python client library? It complains about missing AD credentials, but I am simply not getting how to pass them over. I am working in LoD:

https://handsonlabs.netapp.com/lab/ontapapi (SL10599)

 

Here is what I am trying to do:

print("--> Starting CIFS server delete operation")
try:
	cifs = CifsService.find(name="PRIMARY_SVM_01")
	cifs.from_dict(
	{
	  "svm": {
	    "name": "primary_svm_01"
	  },
	  "ad_domain": {
	    "fqdn": "demo.netapp.com",
	    "user": "Administrator@demo.netapp.com", 
	    "password": "<guesswhatthatcouldbe:D>"
	  }
	})
	cifs.delete()
	print("--> CIFS server {} deleted successfully".format(cifs.name))
except NetAppRestError as err:
	print("--> Error: CIFS server was not deleted:\n{}".format(err))
print("")

 

And here is the debug output:

‌--> Starting CIFS server delete operation
DEBUG:urllib3.util.retry:Converted retries value: 5 -> Retry(total=5, connect=None, read=None, redirect=None, status=None)
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): cluster1.demo.netapp.com:443
DEBUG:urllib3.connectionpool:https://cluster1.demo.netapp.com:443 "GET /api/protocols/cifs/services?name=PRIMARY_SVM_01 HTTP/1.1" 200 579
DEBUG:netapp_ontap.utils:
-----------REQUEST-----------
GET https://cluster1.demo.netapp.com:443/api/protocols/cifs/services?name=PRIMARY_SVM_01
User-Agent: python-requests/2.23.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
X-Dot-Client-App: netapp-ontap-python-9.7.0
Authorization: Basic YWRtaW46TmV0YXBwMSE=
None
-----------------------------

-----------RESPONSE-----------
200 OK
Date: Wed, 18 Mar 2020 06:45:40 GMT
Server: libzapid-httpd
X-Content-Type-Options: nosniff
Cache-Control: no-cache,no-store,must-revalidate
Content-Length: 579
Content-Type: application/hal+json
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
{
  "records": [
    {
      "svm": {
        "uuid": "513ab210-687a-11ea-8d2a-005056819f1b",
        "name": "primary_svm_01",
        "_links": {
          "self": {
            "href": "/api/svm/svms/513ab210-687a-11ea-8d2a-005056819f1b"
          }
        }
      },
      "name": "PRIMARY_SVM_01",
      "_links": {
        "self": {
          "href": "/api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b"
        }
      }
    }
  ],
  "num_records": 1,
  "_links": {
    "self": {
      "href": "/api/protocols/cifs/services?name=PRIMARY_SVM_01"
    }
  }
}
------------------------------
DEBUG:urllib3.util.retry:Converted retries value: 5 -> Retry(total=5, connect=None, read=None, redirect=None, status=None)
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): cluster1.demo.netapp.com:443
DEBUG:urllib3.connectionpool:https://cluster1.demo.netapp.com:443 "GET /api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b HTTP/1.1" 200 768
DEBUG:netapp_ontap.utils:
-----------REQUEST-----------
GET https://cluster1.demo.netapp.com:443/api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b
User-Agent: python-requests/2.23.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
X-Dot-Client-App: netapp-ontap-python-9.7.0
Authorization: Basic YWRtaW46TmV0YXBwMSE=
None
-----------------------------

-----------RESPONSE-----------
200 OK
Date: Wed, 18 Mar 2020 06:45:40 GMT
Server: libzapid-httpd
X-Content-Type-Options: nosniff
Cache-Control: no-cache,no-store,must-revalidate
Content-Length: 768
Content-Type: application/hal+json
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
{
  "svm": {
    "uuid": "513ab210-687a-11ea-8d2a-005056819f1b",
    "name": "primary_svm_01",
    "_links": {
      "self": {
        "href": "/api/svm/svms/513ab210-687a-11ea-8d2a-005056819f1b"
      }
    }
  },
  "name": "PRIMARY_SVM_01",
  "ad_domain": {
    "fqdn": "DEMO.NETAPP.COM",
    "organizational_unit": "CN=Computers"
  },
  "enabled": true,
  "comment": "Created with ONTAP PYL",
  "security": {
    "restrict_anonymous": "no_enumeration",
    "smb_signing": false,
    "smb_encryption": false,
    "kdc_encryption": false
  },
  "netbios": {
    "wins_servers": [
    ],
    "enabled": false
  },
  "default_unix_user": "pcuser",
  "_links": {
    "self": {
      "href": "/api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b"
    }
  }
}
------------------------------
DEBUG:netapp_ontap.utils:
-----------REQUEST-----------
GET https://cluster1.demo.netapp.com:443/api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b
User-Agent: python-requests/2.23.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
X-Dot-Client-App: netapp-ontap-python-9.7.0
Authorization: Basic YWRtaW46TmV0YXBwMSE=
None
-----------------------------

-----------RESPONSE-----------
200 OK
Date: Wed, 18 Mar 2020 06:45:40 GMT
Server: libzapid-httpd
X-Content-Type-Options: nosniff
Cache-Control: no-cache,no-store,must-revalidate
Content-Length: 768
Content-Type: application/hal+json
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
{
  "svm": {
    "uuid": "513ab210-687a-11ea-8d2a-005056819f1b",
    "name": "primary_svm_01",
    "_links": {
      "self": {
        "href": "/api/svm/svms/513ab210-687a-11ea-8d2a-005056819f1b"
      }
    }
  },
  "name": "PRIMARY_SVM_01",
  "ad_domain": {
    "fqdn": "DEMO.NETAPP.COM",
    "organizational_unit": "CN=Computers"
  },
  "enabled": true,
  "comment": "Created with ONTAP PYL",
  "security": {
    "restrict_anonymous": "no_enumeration",
    "smb_signing": false,
    "smb_encryption": false,
    "kdc_encryption": false
  },
  "netbios": {
    "wins_servers": [
    ],
    "enabled": false
  },
  "default_unix_user": "pcuser",
  "_links": {
    "self": {
      "href": "/api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b"
    }
  }
}
------------------------------
DEBUG:urllib3.connectionpool:https://cluster1.demo.netapp.com:443 "DELETE /api/protocols/cifs/services/513ab210-687a-11ea-8d2a-005056819f1b HTTP/1.1" 202 189
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): cluster1.demo.netapp.com:443
DEBUG:urllib3.connectionpool:https://cluster1.demo.netapp.com:443 "GET /api/cluster/jobs/154221a4-68e4-11ea-87e9-00505681f8b5 HTTP/1.1" 200 619
INFO:netapp_ontap.utils:Job (failure): In order to delete an Active Directory machine account for the CIFS server, you must supply the name and password of a Windows account with sufficient privileges to remove computers from the "DEMO.NETAPP.COM" domain. . Timeout remaining: 30.
--> Error: CIFS server was not deleted:
Job failed: In order to delete an Active Directory machine account for the CIFS server, you must supply the name and password of a Windows account with sufficient privileges to remove computers from the "DEMO.NETAPP.COM" domain.

 

1 ACCEPTED SOLUTION

RobertBlackhart
2,374 Views

The CIFS Services DELETE API requires that the credentials are passed in the body of the request. So your code should look a bit like this:

 

print("--> Starting CIFS server delete operation")
try:
    cifs = CifsService.find(name="PRIMARY_SVM_01")
    cifs.delete(body={
        "ad_domain": {
            "fqdn": "demo.netapp.com",
            "user": "Administrator@demo.netapp.com", 
            "password": "<guesswhatthatcouldbe:D>"
        }
    })
    print("--> CIFS server {} deleted successfully".format(cifs.name))
except NetAppRestError as err:
    print("--> Error: CIFS server was not deleted:\n{}".format(err))
print("")

 

View solution in original post

1 REPLY 1

RobertBlackhart
2,375 Views

The CIFS Services DELETE API requires that the credentials are passed in the body of the request. So your code should look a bit like this:

 

print("--> Starting CIFS server delete operation")
try:
    cifs = CifsService.find(name="PRIMARY_SVM_01")
    cifs.delete(body={
        "ad_domain": {
            "fqdn": "demo.netapp.com",
            "user": "Administrator@demo.netapp.com", 
            "password": "<guesswhatthatcouldbe:D>"
        }
    })
    print("--> CIFS server {} deleted successfully".format(cifs.name))
except NetAppRestError as err:
    print("--> Error: CIFS server was not deleted:\n{}".format(err))
print("")

 

Public