forked from dougsland/ovirt-restapi-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-delete.py
43 lines (37 loc) · 1.37 KB
/
sample-delete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
#
# Copyright (C) 2011
#
# Douglas Schilling Landgraf <dougsland@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import urllib2
import base64
import sys
# Example
ADDR = "192.168.123.176"
API_PORT = "8443"
USER = "rhevm@ad.rhev3.com"
PASSWD = "T0pSecreT!"
# Setting URL
URL = "https://" + ADDR + ":" + API_PORT + "/api/datacenters/f66b9b1c-c428-474f-9966-74aab4b0447d"
request = urllib2.Request(URL)
print "Connecting to: " + URL
base64string = base64.encodestring('%s:%s' % (USER, PASSWD)).strip()
request.add_header("Authorization", "Basic %s" % base64string)
request.get_method = lambda: 'DELETE'
try:
xmldata = urllib2.urlopen(request).read()
except urllib2.URLError, e:
print "Error: cannot connect to REST API: %s" % (e)
print "Possible errors: "
print "\t- Are you trying to remove an non existing item?"
print "\t- Try to login using the same user/pass by the Admin Portal and check the error!"
sys.exit(2)