Skip to content

Commit 90771e2

Browse files
committed
Merge pull request dnaeon#1 from dnaeon/master
Pull in new changes
2 parents 603dfc9 + 07a60cf commit 90771e2

File tree

16 files changed

+712
-50
lines changed

16 files changed

+712
-50
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Python vSphere Client with a dialog(1) interface
22
================================================
33

4+
.. image:: https://badges.gitter.im/Join%20Chat.svg
5+
:alt: Join the chat at https://gitter.im/dnaeon/pvc
6+
:target: https://gitter.im/dnaeon/pvc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
7+
48
PVC is an interactive text-mode VMware vSphere Client with a
59
`dialog(1)`_ interface for GNU/Linux systems built on top of the
610
`pyVmomi`_ VMware vSphere API Python bindings.

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import sys, os
1616

17+
import pvc
18+
1719
# If extensions (or modules to document with autodoc) are in another directory,
1820
# add these directories to sys.path here. If the directory is relative to the
1921
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -49,9 +51,9 @@
4951
# built documents.
5052
#
5153
# The short X.Y version.
52-
version = '0.1.0'
54+
version = pvc.__version__
5355
# The full version, including alpha/beta/rc tags.
54-
release = '0.1.0'
56+
release = pvc.__version__
5557

5658
# The language for content autogenerated by Sphinx. Refer to documentation
5759
# for a list of supported languages.

docs/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Requirements
1515

1616
The following list provides information about the PVC dependencies.
1717

18-
* `Python 3.2.x or later`_
18+
* `Python 2.7.x, 3.2.x or later`_
1919
* `humanize`_
2020
* `pythondialog`_
2121
* `pyVmomi`_
@@ -81,7 +81,7 @@ as well.
8181

8282
.. _`pip`: https://pypi.python.org/pypi/pip
8383
.. _`Github`: https://github.com/dnaeon/pvc
84-
.. _`Python 3.2.x or later`: http://python.org/
84+
.. _`Python 2.7.x, 3.2.x or later`: http://python.org/
8585
.. _`humanize`: https://github.com/jmoiron/humanize
8686
.. _`pythondialog`: http://pythondialog.sourceforge.net/
8787
.. _`pyVmomi`: https://github.com/vmware/pyvmomi

setup.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from __future__ import print_function
2+
13
import re
24
import ast
5+
import sys
36

47
from setuptools import setup, find_packages
58

@@ -11,10 +14,18 @@
1114
f.read().decode('utf-8')).group(1))
1215
)
1316

17+
if (2, 7) <= sys.version_info < (3, 0):
18+
dialog_package = 'python2-pythondialog'
19+
elif sys.version_info >= (3, 0):
20+
dialog_package = 'pythondialog'
21+
else:
22+
print('Unsupported Python version')
23+
sys.exit(1)
24+
1425
setup(
1526
name='pvc',
1627
version=version,
17-
description='Python vSphere Client',
28+
description='Python vSphere Client with a dialog(1) interface',
1829
long_description=open('README.rst').read(),
1930
author='Marin Atanasov Nikolov',
2031
author_email='[email protected]',
@@ -27,8 +38,8 @@
2738
'src/pvc-tui',
2839
],
2940
install_requires=[
41+
'{} >= 3.2.1'.format(dialog_package),
3042
'humanize >= 0.5.1',
31-
'pythondialog >= 3.2.1',
3243
'pyvmomi >= 5.5.0-2014.1.1',
3344
'requests >= 2.6.0',
3445
'vconnector >= 0.3.7',

src/pvc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.1'
1+
__version__ = '0.1.3'

src/pvc/core.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
2828
"""
2929

30+
import pyVmomi
31+
3032
import requests
3133
requests.packages.urllib3.disable_warnings()
3234

@@ -129,24 +131,42 @@ def login(self):
129131
self.dialog.set_background_title(background_title)
130132
return True
131133
except Exception as e:
134+
if isinstance(e, pyVmomi.vim.MethodFault):
135+
msg = e.msg
136+
else:
137+
msg = e
138+
132139
self.dialog.msgbox(
133140
title='Login failed',
134-
text='Failed to login to {}\n\n{}\n'.format(self.agent.host, e.msg)
141+
text='Failed to login to {}\n\n{}\n'.format(self.agent.host, msg)
135142
)
136143

137-
def run(self):
138-
self.about()
139-
if not self.login():
140-
return
144+
def disconnect(self):
145+
"""
146+
Disconnect from the remote vSphere host
141147
142-
home = pvc.widget.home.HomeWidget(
143-
agent=self.agent,
144-
dialog=self.dialog
145-
)
146-
home.display()
148+
"""
149+
if not self.agent:
150+
return
147151

148152
self.dialog.infobox(
149153
title='Disconnecting Connection',
150154
text='Disconnecting from {} ...'.format(self.agent.host)
151155
)
152156
self.agent.disconnect()
157+
158+
def run(self):
159+
try:
160+
self.about()
161+
if not self.login():
162+
return
163+
164+
home = pvc.widget.home.HomeWidget(
165+
agent=self.agent,
166+
dialog=self.dialog
167+
)
168+
home.display()
169+
except KeyboardInterrupt:
170+
pass
171+
finally:
172+
self.disconnect()

src/pvc/widget/common.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'choose_datacenter', 'choose_cluster', 'choose_datastore',
4949
'inventory_search_by_dns', 'inventory_search_by_ip',
5050
'inventory_search_by_uuid', 'datacenter_menu', 'remove',
51+
'choose_network',
5152
]
5253

5354

@@ -913,6 +914,67 @@ def choose_datastore(agent, dialog, obj):
913914
return [ds['obj'] for ds in properties if ds['name'] == tag].pop()
914915

915916

917+
def choose_network(agent, dialog, obj):
918+
"""
919+
Prompts the user to choose a network
920+
921+
Args:
922+
agent (VConnector): A VConnector instance
923+
dialog (dialog.Dailog): A Dialog instance
924+
obj (vim.ManagedEntity): A Managed Entity
925+
926+
Returns:
927+
A vim.Network managed entity if a network has been
928+
chosen
929+
930+
Return None if no network has been selected or
931+
there are no networks existing
932+
933+
"""
934+
title = '{} ({})'.format(obj.name, obj.__class__.__name__)
935+
936+
dialog.infobox(
937+
title=title,
938+
text='Retrieving information ...'
939+
)
940+
941+
if not hasattr(obj, 'network'):
942+
return
943+
944+
view = agent.get_list_view(obj.network)
945+
properties = agent.collect_properties(
946+
view_ref=view,
947+
obj_type=pyVmomi.vim.Network,
948+
path_set=['name', 'summary.accessible'],
949+
include_mors=True
950+
)
951+
view.DestroyView()
952+
953+
if not properties:
954+
return
955+
956+
items = [
957+
pvc.widget.radiolist.RadioListItem(
958+
tag=network['name'],
959+
description='Accessible' if network['summary.accessible'] else 'Not Accessible',
960+
) for network in properties
961+
]
962+
963+
radiolist = pvc.widget.radiolist.RadioList(
964+
items=items,
965+
dialog=dialog,
966+
title='Choose Network',
967+
text='Choose a network from the list below'
968+
)
969+
970+
code, tag = radiolist.display()
971+
972+
if code in (dialog.CANCEL, dialog.ESC) or not tag:
973+
return
974+
975+
return [network['obj'] for network in properties if network['name'] == tag].pop()
976+
977+
916978
def inventory_search_by_dns(agent, dialog, vm_search):
917979
"""
918980
Search inventory for managed objects by their DNS name

src/pvc/widget/datacenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def create_cluster(self):
291291
name=name,
292292
spec=pyVmomi.vim.cluster.ConfigSpecEx()
293293
)
294-
except Exception as e:
294+
except pyVmomi.vim.MethodFault as e:
295295
self.dialog.msgbox(
296296
title=self.title,
297297
text=e.msg

src/pvc/widget/debug.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"""
2929

3030
import code
31+
import readline
3132

3233
__all__ = ['DebugWidget']
3334

0 commit comments

Comments
 (0)