[Cloud-init-dev] [Merge] ~adobrawy/cloud-init:migrate-lp-to-github into cloud-init:master

2019-12-17 Thread Adam Dobrawy
Adam Dobrawy has proposed merging ~adobrawy/cloud-init:migrate-lp-to-github 
into cloud-init:master.

Commit message:
lp-to-git-users: adding ad-m

Mapped from adobrawy


Requested reviews:
  cloud-init Commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/376922
-- 
Your team cloud-init Commiters is requested to review the proposed merge of 
~adobrawy/cloud-init:migrate-lp-to-github into cloud-init:master.
diff --git a/tools/.lp-to-git-user b/tools/.lp-to-git-user
index 3b4b873..6fa75b2 100644
--- a/tools/.lp-to-git-user
+++ b/tools/.lp-to-git-user
@@ -1,4 +1,5 @@
 {
+ "adobrawy": "ad-m",
  "ahosmanmsft": "AOhassan",
  "bitfehler": "bitfehler",
  "chad.smith": "blackboxsw",
___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~adobrawy/cloud-init:swap-linux into cloud-init:master

2018-09-11 Thread Adam Dobrawy
Adam Dobrawy has proposed merging ~adobrawy/cloud-init:swap-linux into 
cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354680

xfs, which is default on CentOS7 doesn't handle fallocate correctly when used 
with swapfiles.
Therefore we need to check if the FS is fallocate-safe. Not sure if other FS' 
are affected.
https://unix.stackexchange.com/questions/294600/i-cant-enable-swap-space-on-centos-7#294605

This is a friendly transfer of the pull-request originally reported on GitHub: 
https://github.com/cloud-init/cloud-init/pull/11
I work with Krzysztof Biernat and I have obtained permission from him for such 
an operation.
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~adobrawy/cloud-init:swap-linux into cloud-init:master.
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 339baba..e54e753 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -249,14 +249,22 @@ def setup_swapfile(fname, size=None, maxsize=None):
 msg = "creating swap file '%s' of %sMB" % (fname, mbsize)
 try:
 util.ensure_dir(tdir)
+# Check if filesystem is safe for fallocate
+fname_fs_type = util.get_mount_info(fname)[1]
+if fname_fs_type in ['xfs']:
+create_swapfile_command = 'dd if=/dev/zero "of=$1" bs=1M "count=$2"'
+else:
+create_swapfile_command = 'fallocate -l "${2}M" "$1"'
+
 util.log_time(LOG.debug, msg, func=util.subp,
   args=[['sh', '-c',
 ('rm -f "$1" && umask 0066 && '
- '{ fallocate -l "${2}M" "$1" || '
- ' dd if=/dev/zero "of=$1" bs=1M "count=$2"; } && '
- 'mkswap "$1" || { r=$?; rm -f "$1"; exit $r; }'),
+ '%s && '
+ 'mkswap "$1" || { r=$?; rm -f "$1"; exit $r; }' %
+ create_swapfile_command),
  'setup_swap', fname, mbsize]])
 
+
 except Exception as e:
 raise IOError("Failed %s: %s" % (msg, e))
 
___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~adobrawy/cloud-init:rbx-datasource into cloud-init:master

2018-09-11 Thread Adam Dobrawy
Adam Dobrawy has proposed merging ~adobrawy/cloud-init:rbx-datasource into 
cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354679
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~adobrawy/cloud-init:rbx-datasource into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceRbxCloud.py b/cloudinit/sources/DataSourceRbxCloud.py
new file mode 100644
index 000..736b860
--- /dev/null
+++ b/cloudinit/sources/DataSourceRbxCloud.py
@@ -0,0 +1,343 @@
+# vi: ts=4 expandtab
+# Copyright (C) 2016 Warsaw Data Center
+#
+# Author: Malwina Leis 
+# Author: Grzegorz Brzeski 
+#
+# This file is part of cloud-init. See LICENSE file for license information.
+'''Datasource for  rootbox / hyperone cloud platforms'''
+import errno
+import os
+import os.path
+
+import socket
+
+from cloudinit import log as logging
+from cloudinit import sources
+from cloudinit import util
+from cloudinit.netinfo import netdev_info
+
+LOG = logging.getLogger(__name__)
+
+
+def _read_file(filepath):
+try:
+content = util.load_file(filepath).strip()
+except IOError:
+util.logexc(LOG, 'Failed accessing file: ' + filepath)
+return None
+return content
+
+
+def _get_meta_data(filepath):
+content = _read_file(filepath)
+if not content:
+return None
+
+try:
+content = util.load_json(content)
+except Exception:
+util.logexc(LOG, 'Failed parsing meta data file from json.')
+return None
+
+return content
+
+
+def read_user_data_callback(mount_dir, distro):
+'''
+Description:
+This callback will be applied by util.mount_cb() on the mounted
+file.
+
+Input:
+mount_dir - Mount directory
+
+Returns:
+User Data
+
+'''
+
+meta_data = _get_meta_data(os.path.join(mount_dir, 'cloud.json'))
+user_data = _read_file(os.path.join(mount_dir, 'user.data'))
+additional_metadata = meta_data['additionalMetadata']
+
+data = {
+'userdata': user_data,
+'metadata': {
+'instance-id': meta_data['vm']['_id'],
+# This puts keys also for root
+# 'public-keys': meta_data['additionalMetadata']['sshKeys'],
+'local-hostname': meta_data['vm']['name']
+},
+'cfg': {
+'ssh_pwauth': True,
+'disable_root': True,
+'system_info': {
+'default_user': {
+'name': additional_metadata.get('username', 'guru'),
+'gecos': additional_metadata.get('username', 'guru'),
+'sudo': ['ALL=(ALL) NOPASSWD:ALL'],
+'lock_passwd': False,
+'ssh_authorized_keys': additional_metadata['sshKeys'],
+'shell': '/bin/bash'
+}
+},
+'runcmd': []
+}
+}
+
+hosts_path = '/etc/hosts'
+hosts = _read_file(hosts_path)
+if hosts:
+data['cfg']['manage_etc_hosts'] = False
+LOG.debug('/etc/hosts exists - set manage_etc_hosts to False')
+else:
+data['cfg']['manage_etc_hosts'] = True
+LOG.debug('/etc/hosts does not exists - set manage_etc_hosts to True')
+
+if meta_data['netadp']:
+netdata = generate_eni(meta_data['netadp'], distro)
+data['metadata']['network-interfaces'] = netdata['eni']
+data['cfg']['runcmd'] = netdata['cmd']
+
+username = meta_data['additionalMetadata'].get('username', 'guru')
+password = meta_data['additionalMetadata']['password']['sha512']
+data['cfg']['runcmd'].append("echo '{username}:{password}' | chpasswd -e"
+ .format(username=username,
+ password=password))
+
+LOG.debug('returning DATA object:')
+LOG.debug(data)
+
+return data
+
+
+def generate_eni(netadp, distro):
+LOG.debug("RBX: generate_eni")
+LOG.debug(netadp)
+
+netdevices = netdev_info()
+
+ENI = []
+CMD = []
+
+ARPING = "arping -c 2 -S "
+ARPING_RHEL = "arping -c 2 -s "
+
+LOG.debug("Generating eni for distro: %s", distro)
+if distro == 'rhel':
+ARPING = ARPING_RHEL
+
+ENI.append('auto lo')
+ENI.append('iface lo inet loopback')
+ENI.append('')
+
+default_nic = [
+n
+for n in sorted(netadp, key=lambda k: k['_id'])
+if n.get('default_gw') == "true"
+]
+if (not default_nic) and netadp:
+default_nic = [sorted(netadp, key=lambda k: k['_id'])[0]]
+LOG.debug("Default interface mac: %s",
+  default_nic[0].get('macaddress'))
+else:
+LOG.debug("No netadp to configure")
+return None
+LOG.debug("Default nic: %s", default_nic[