Skip to content

Instantly share code, notes, and snippets.

@artn
Last active August 28, 2017 04:58
Show Gist options
  • Save artn/701c6bd882589f35250f4985700ff0c3 to your computer and use it in GitHub Desktop.
Save artn/701c6bd882589f35250f4985700ff0c3 to your computer and use it in GitHub Desktop.
datasource:
CloudStack: {}
None: {}
datasource_list:
- CloudStack
--- DataSourceCloudStack.py.orig 2017-08-25 16:00:02.261852357 +0900
+++ DataSourceCloudStack.py 2017-08-25 16:21:45.750044514 +0900
@@ -137,30 +137,31 @@
def get_dhclient_d():
- # find lease files directory
- supported_dirs = ["/var/lib/dhclient", "/var/lib/dhcp"]
- for d in supported_dirs:
- if os.path.exists(d):
- LOG.debug("Using %s lease directory", d)
- return d
+ # find lease files directories
+ supported_dirs = ["/var/lib/dhclient", "/var/lib/dhcp", "/var/lib/NetworkManager"]
+ existing_dirs = filter(lambda d:os.path.exists(d), supported_dirs)
+ if len(existing_dirs) > 0:
+ LOG.debug("Using %s lease directory", existing_dirs)
+ return existing_dirs
return None
def get_latest_lease():
# find latest lease file
- lease_d = get_dhclient_d()
- if not lease_d:
+ lease_dirs = get_dhclient_d()
+ if not lease_dirs:
return None
- lease_files = os.listdir(lease_d)
- latest_mtime = -1
latest_file = None
- for file_name in lease_files:
- if file_name.endswith(".lease") or file_name.endswith(".leases"):
- abs_path = os.path.join(lease_d, file_name)
- mtime = os.path.getmtime(abs_path)
- if mtime > latest_mtime:
- latest_mtime = mtime
- latest_file = abs_path
+ for lease_d in lease_dirs:
+ lease_files = os.listdir(lease_d)
+ latest_mtime = -1
+ for file_name in lease_files:
+ if file_name.endswith(".lease") or file_name.endswith(".leases"):
+ abs_path = os.path.join(lease_d, file_name)
+ mtime = os.path.getmtime(abs_path)
+ if mtime > latest_mtime:
+ latest_mtime = mtime
+ latest_file = abs_path
return latest_file
#!/bin/sh
curl https://gist.githubusercontent.com/artn/701c6bd882589f35250f4985700ff0c3/raw/10_cloudstack.cfg > /etc/cloud/cloud.cfg.d/10_cloudstack.cfg
cd /usr/lib/python2.7/site-packages/cloudinit/sources
curl https://gist.githubusercontent.com/artn/701c6bd882589f35250f4985700ff0c3/raw/cloud-init-network-manager.patch | patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment