~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/common/utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-03-30 11:14:57 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20150330111457-kr4ju3guf22m4vbz
Tags: 2015.1~b3-0ubuntu1
* New upstream release.
  + d/control: 
    - Align with upstream dependencies.
    - Add dh-python to build-dependencies.
    - Add psmisc as a dependency. (LP: #1358820)
  + d/p/fix-requirements.patch: Rediffed.
  + d/ironic-conductor.init.in: Fixed typos in LSB headers,
    thanks to JJ Asghar. (LP: #1429962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import re
27
27
import shutil
28
28
import tempfile
29
 
import uuid
30
29
 
31
30
import netaddr
32
 
from oslo.utils import excutils
33
31
from oslo_concurrency import processutils
34
32
from oslo_config import cfg
 
33
from oslo_utils import excutils
35
34
import paramiko
36
35
import six
37
36
 
157
156
            raise
158
157
 
159
158
 
160
 
def is_int_like(val):
161
 
    """Check if a value looks like an int."""
162
 
    try:
163
 
        return str(int(val)) == str(val)
164
 
    except Exception:
165
 
        return False
166
 
 
167
 
 
168
159
def is_valid_boolstr(val):
169
160
    """Check if the provided string is a valid bool string or not."""
170
161
    boolstrs = ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0')
182
173
 
183
174
    """
184
175
    m = "[0-9a-f]{2}(:[0-9a-f]{2}){5}$"
185
 
    if isinstance(address, six.string_types) and re.match(m, address.lower()):
186
 
        return True
187
 
    return False
 
176
    return (isinstance(address, six.string_types) and
 
177
            re.match(m, address.lower()))
 
178
 
 
179
 
 
180
def is_hostname_safe(hostname):
 
181
    """Determine if the supplied hostname is RFC compliant.
 
182
 
 
183
    Check that the supplied hostname conforms to:
 
184
        * http://en.wikipedia.org/wiki/Hostname
 
185
        * http://tools.ietf.org/html/rfc952
 
186
        * http://tools.ietf.org/html/rfc1123
 
187
 
 
188
    Also allow "." because what kind of hostname doesn't allow that.
 
189
 
 
190
    :param hostname: The hostname to be validated.
 
191
    :returns: True if valid. False if not.
 
192
 
 
193
    """
 
194
    m = '^[a-z0-9]([a-z0-9\-\.]{0,61}[a-z0-9])?$'
 
195
    return (isinstance(hostname, six.string_types) and
 
196
           (re.match(m, hostname) is not None))
188
197
 
189
198
 
190
199
def validate_and_normalize_mac(address):
472
481
    return value.rstrip(chars) or value
473
482
 
474
483
 
475
 
def generate_uuid():
476
 
    return str(uuid.uuid4())
477
 
 
478
 
 
479
 
def is_uuid_like(val):
480
 
    """Returns validation of a value as a UUID.
481
 
 
482
 
    For our purposes, a UUID is a canonical form string:
483
 
    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
484
 
 
485
 
    """
486
 
    try:
487
 
        return str(uuid.UUID(val)) == val
488
 
    except (TypeError, ValueError, AttributeError):
489
 
        return False
490
 
 
491
 
 
492
484
def mount(src, dest, *args):
493
485
    """Mounts a device/image file on specified location.
494
486