Skip to content

Commit

Permalink
Merge pull request #130 from ryran/app-design-editing-nics
Browse files Browse the repository at this point in the history
new vm-editing cmds (#128) & tilde-prefixed filename support (#129)
  • Loading branch information
ryran authored Feb 14, 2017
2 parents 2631364 + 0716ff9 commit b31e8de
Show file tree
Hide file tree
Showing 5 changed files with 652 additions and 68 deletions.
4 changes: 2 additions & 2 deletions modules/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
prog = 'ravshello'

# Version info
__version__ = '1.15.2'
__date__ = '2017/02/07'
__version__ = '1.16.0'
__date__ = '2017/02/13'
version = "{} v{} last mod {}".format(prog, __version__, __date__)

# Defaults
Expand Down
16 changes: 13 additions & 3 deletions modules/ravello_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,20 @@ def purge_app_cache(self, appId=None):
else:
self.appCache = {}

def get_app(self, appId):
if appId not in self.appCache or ui.get_timestamp_proximity(self.appCache[appId]['ts']) < -60:
def get_app(self, appId, aspect=None):
if appId not in self.appCache or ui.get_timestamp_proximity(self.appCache[appId]['ts']) < -120:
self.update_app_cache(appId)
return self.appCache[appId]['definition']
if aspect:
return self.appCache[appId]['definition'][aspect]
else:
return self.appCache[appId]['definition']

def get_vm(self, appId, vmId, aspect):
if appId not in self.appCache or ui.get_timestamp_proximity(self.appCache[appId]['ts']) < -120:
self.update_app_cache(appId)
for vm in self.appCache[appId]['definition'][aspect]['vms']:
if vm['id'] == vmId:
return vm

def update_user_cache(self):
self._userCache_tstamp = time()
Expand Down
2 changes: 1 addition & 1 deletion modules/string_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def slow_print(string, interval=.02):
print()

def replace_bad_chars_with_underscores(string,
pattern='[^A-Za-z0-9:_.-]', repl='_', count=0):
pattern='[^A-Za-z0-9:_.~-]', repl='_', count=0):
"""Perform some simple character substitution on *string*."""
return sub(pattern, repl, string, count)

Expand Down
17 changes: 17 additions & 0 deletions modules/ui_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sys import stdout
import subprocess
import json
import re

# Custom modules
from . import cfg
Expand Down Expand Up @@ -139,6 +140,7 @@ def print_obj(obj, desc, output='@EDITOR', tmpPrefix='', suffix='.json'):
tmp.flush()
subprocess.call([cmd, tmp.name])
else:
output = path.expanduser(output)
if suffix:
output += suffix
try:
Expand Down Expand Up @@ -227,3 +229,18 @@ def expand_secs_to_ywdhms(seconds):
unit = unit.rstrip('s')
result.append("{} {}".format(value, unit))
return ', '.join(result)

def validate_ipv4_addr(ipstring):
"""Ensure that string is a valid IPv4 address in decimal."""
pieces = ipstring.split('.')
if len(pieces) != 4:
return False
try:
return all(0<=int(p)<256 for p in pieces)
except ValueError:
return False

def validate_mac_addr(macstring):
"""Ensure that string is a valid MAC address in standard format."""
regexstr = "[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}$"
return re.match(regexstr, macstring.lower())
Loading

0 comments on commit b31e8de

Please sign in to comment.