Skip to content

Commit 67c25e1

Browse files
authored
Merge pull request #56 from tianhao64/master
vSphere 6.7 Release
2 parents 1ea926a + f1032b4 commit 67c25e1

17 files changed

+860
-2
lines changed

doc/client.zip

45.3 KB
Binary file not shown.

doc/vmc.zip

-115 KB
Binary file not shown.

lib/vapi-client-bindings/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a href='vapi_client_bindings-1.1.0-py2.py3-none-any.whl'>vapi_client_bindings-1.1.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_client_bindings-1.2.0-py2.py3-none-any.whl'>vapi_client_bindings-1.2.0-py2.py3-none-any.whl</a><br />
Binary file not shown.
Binary file not shown.

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pyVmomi >= 6.5
22
suds ; python_version < '3'
33
suds-jurko ; python_version >= '3.0'
44
tabulate
5-
vapi-client-bindings == 1.1.0
5+
vapi-client-bindings == 1.2.0
66
vmc-client-bindings == 1.1.0
77
vapi-vmc-client
8+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This directory contains samples for Backup Restore APIs:
2+
3+
* List all backup jobs
4+
* CRUD operations on backup schedule
5+
6+
Running the samples
7+
8+
$ python <sample-dir>/<sample>.py --server <vCenter Server IP> --username <username> --password <password> <additional-sample-parameters>
9+
10+
The additional sample parameters are as follows (all parameters can be displayed for any sample using option --help)
11+
12+
* backup_schedule.py --location <location URL> --location_user <location-user> location_password <location-password>
13+
14+
* Testbed Requirement:
15+
- 1 vCenter Server
16+
- Backup server reachable through any of the supported protocols FTP/FTPS/SCP/HTTP/HTTPS
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2017. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
* *******************************************************
6+
*
7+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12+
"""
13+
14+
__author__ = 'VMware, Inc.'
15+
__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
16+
17+
# Required to distribute different parts of this
18+
# package as multiple distribution
19+
try:
20+
import pkg_resources
21+
22+
pkg_resources.declare_namespace(__name__)
23+
except ImportError:
24+
from pkgutil import extend_path
25+
26+
__path__ = extend_path(__path__, __name__) # @ReservedAssignment
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
6+
* SPDX-License-Identifier: MIT
7+
* *******************************************************
8+
*
9+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14+
"""
15+
16+
__author__ = 'VMware, Inc.'
17+
__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
18+
__vcenter_version__ = '6.7+'
19+
20+
from tabulate import tabulate
21+
from samples.vsphere.common import sample_cli
22+
from samples.vsphere.common import sample_util
23+
from samples.vsphere.common import vapiconnect
24+
from com.vmware.appliance.recovery.backup.job_client import Details
25+
26+
27+
class BackupJobList(object):
28+
"""
29+
Demonstrates backup job list operation
30+
31+
Retrieves backup job details from vCenter and prints the data in
32+
tabular format
33+
34+
Prerequisites:
35+
- vCenter
36+
- Backup operation is performed on the vCenter either manually or
37+
by scheduled backups
38+
"""
39+
40+
def __init__(self):
41+
self.stub_config = None
42+
43+
def setup(self):
44+
parser = sample_cli.build_arg_parser()
45+
args = sample_util.process_cli_args(parser.parse_args())
46+
47+
# Connect to vAPI services
48+
self.stub_config = vapiconnect.connect(
49+
host=args.server,
50+
user=args.username,
51+
pwd=args.password,
52+
skip_verification=args.skipverification)
53+
54+
def run(self):
55+
details_client = Details(self.stub_config)
56+
job_list = details_client.list()
57+
58+
table = []
59+
for info in job_list.itervalues():
60+
row = [info.start_time.strftime("%b %d %Y %H:%M"),
61+
info.duration,
62+
info.type,
63+
info.status,
64+
info.location]
65+
table.append(row)
66+
headers = ["Start time", "Duration", "Type", "Status", "Location"]
67+
print(tabulate(table, headers))
68+
69+
70+
def main():
71+
backup_job_list = BackupJobList()
72+
backup_job_list.setup()
73+
backup_job_list.run()
74+
75+
76+
if __name__ == '__main__':
77+
main()
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
6+
* SPDX-License-Identifier: MIT
7+
* *******************************************************
8+
*
9+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14+
"""
15+
16+
__author__ = 'VMware, Inc.'
17+
__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
18+
__vcenter_version__ = '6.7+'
19+
20+
21+
from samples.vsphere.common import sample_cli
22+
from samples.vsphere.common import sample_util
23+
from samples.vsphere.common import vapiconnect
24+
from tabulate import tabulate
25+
26+
from com.vmware.appliance.recovery.backup_client import Schedules
27+
28+
29+
class BackupSchedule(object):
30+
"""
31+
Demonstrates backup schedule operations
32+
33+
Prerequisites:
34+
- vCenter
35+
- Backup server (ftp/ftps/http/https/scp)
36+
"""
37+
38+
def __init__(self):
39+
self.stub_config = None
40+
41+
# Scheudle backup to run on weekdays at 10:30 pm
42+
self.days = ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"]
43+
self.hour = 22
44+
self.minute = 30
45+
46+
# Retain last 30 backups
47+
self.max_count = 30
48+
49+
self._schedule_id = 'test_schedule'
50+
51+
52+
def setup(self):
53+
parser = sample_cli.build_arg_parser()
54+
55+
parser.add_argument('-location', '--location',
56+
required=True,
57+
action='store',
58+
help='URL of the backup location')
59+
parser.add_argument('--location_user',
60+
required=True,
61+
action='store',
62+
help='Username for the given location')
63+
parser.add_argument('--location_password',
64+
required=True,
65+
action='store',
66+
help='Password for the given location')
67+
68+
args = sample_util.process_cli_args(parser.parse_args())
69+
self.location = args.location
70+
self.location_user = args.location_user
71+
self.location_password = args.location_password
72+
73+
# Connect to vAPI services
74+
self.stub_config = vapiconnect.connect(
75+
host=args.server,
76+
user=args.username,
77+
pwd=args.password,
78+
skip_verification=args.skipverification)
79+
80+
self.schedule_client = Schedules(self.stub_config)
81+
82+
def run(self):
83+
# Create a backup schedule
84+
self.create_schedule()
85+
86+
# Update the backup schedule to take backup only on weekends
87+
self.days = ["SATURDAY", "SUNDAY"]
88+
self.update_schedule()
89+
90+
# Get the updated backup schedule
91+
self.get_schedule()
92+
93+
# Run backup operation using the scheduled configuration
94+
self.run_backup()
95+
96+
# Delete the backup schedule
97+
self.delete_schedule()
98+
99+
def create_schedule(self):
100+
retention_info = Schedules.RetentionInfo(self.max_count)
101+
recurrence_info = Schedules.RecurrenceInfo(
102+
days=self.days,
103+
hour=self.hour,
104+
minute=self.minute)
105+
create_spec = Schedules.CreateSpec(
106+
location=self.location,
107+
location_user=self.location_user,
108+
location_password=self.location_password,
109+
recurrence_info=recurrence_info,
110+
retention_info=retention_info)
111+
112+
self.schedule_client.create(self._schedule_id, create_spec)
113+
114+
def update_schedule(self):
115+
retention_info = Schedules.RetentionInfo(self.max_count)
116+
recurrence_info = Schedules.RecurrenceInfo(
117+
days=self.days,
118+
hour=self.hour,
119+
minute=self.minute)
120+
update_spec = Schedules.UpdateSpec(
121+
location=self.location,
122+
location_user=self.location_user,
123+
location_password=self.location_password,
124+
recurrence_info=recurrence_info,
125+
retention_info=retention_info)
126+
127+
self.schedule_client.update(self._schedule_id, update_spec)
128+
129+
def get_schedule(self):
130+
self.schedule_client = Schedules(self.stub_config)
131+
schedule_spec = self.schedule_client.get(self._schedule_id)
132+
133+
recurrence_info = schedule_spec.recurrence_info
134+
retention_info = schedule_spec.retention_info
135+
136+
table = []
137+
data = [self._schedule_id,
138+
"{}:{}".format(recurrence_info.hour, recurrence_info.minute),
139+
" ".join(recurrence_info.days),
140+
retention_info.max_count]
141+
table.append(data)
142+
headers = ["Schedule ID", "Time", "Days", "Retention"]
143+
print(tabulate(table, headers))
144+
145+
def run_backup(self):
146+
schedule_spec = self.schedule_client.run(self._schedule_id)
147+
148+
def delete_schedule(self):
149+
self.schedule_client.delete(self._schedule_id)
150+
151+
152+
def main():
153+
schedule = BackupSchedule()
154+
schedule.setup()
155+
schedule.run()
156+
157+
if __name__ == '__main__':
158+
main()

0 commit comments

Comments
 (0)