Skip to content

Commit

Permalink
template preparation fix and cluster info (vmware#69)
Browse files Browse the repository at this point in the history
- fix vmware#67 Ubuntu template preparation
- fix vmware#68 node list
- mask password in debug logging
- set password using guest operations
- update tests
- update dependencies
- pika logging set to warning

Signed-off-by: Paco Gomez <contact@pacogomez.com>
  • Loading branch information
pacogomez authored Feb 5, 2018
1 parent e52d5d8 commit 74f68f4
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 79 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
CHANGES
=======

* template preparation fix and cluster info
* updated docs

0.4.0
-----

Expand Down
59 changes: 22 additions & 37 deletions container_service_extension/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,22 @@ def get_cluster_info(self, name, headers, body):
for vm in vms:
node_info = {
'name': vm.get('name'),
'numberOfCpus': vm.VmSpecSection.NumCpus.text,
'memoryMB':
vm.VmSpecSection.MemoryResourceMb.Configured.text,
'numberOfCpus': '',
'memoryMB': '',
'status': VCLOUD_STATUS_MAP.get(int(vm.get('status'))),
'ipAddress': vapp.get_primary_ip(vm.get('name'))
'ipAddress': ''
}
if hasattr(vm, 'VmSpecSection'):
node_info['numberOfCpus'] = vm.VmSpecSection.NumCpus.text
node_info[
'memoryMB'] = \
vm.VmSpecSection.MemoryResourceMb.Configured.text
try:
node_info['ipAddress'] = vapp.get_primary_ip(
vm.get('name'))
except Exception:
LOGGER.debug(
'cannot get ip address for node %s' % vm.get('name'))
if vm.get('name').startswith(TYPE_MASTER):
node_info['node_type'] = 'master'
clusters[0].get('master_nodes').append(node_info)
Expand Down Expand Up @@ -430,17 +440,8 @@ def create_cluster_thread(self):
message='Creating master node for %s(%s)' % (self.cluster_name,
self.cluster_id))
vapp.reload()
add_nodes(
1,
template,
TYPE_MASTER,
self.config,
self.client_tenant,
org,
vdc,
vapp,
self.body,
wait=True)
add_nodes(1, template, TYPE_MASTER, self.config,
self.client_tenant, org, vdc, vapp, self.body)
self.update_task(
TaskStatus.RUNNING,
message='Initializing cluster %s(%s)' % (self.cluster_name,
Expand All @@ -457,17 +458,9 @@ def create_cluster_thread(self):
message='Creating %s node(s) for %s(%s)' %
(self.body['node_count'], self.cluster_name,
self.cluster_id))
add_nodes(
self.body['node_count'],
template,
TYPE_NODE,
self.config,
self.client_tenant,
org,
vdc,
vapp,
self.body,
wait=True)
add_nodes(self.body['node_count'], template, TYPE_NODE,
self.config, self.client_tenant, org, vdc, vapp,
self.body)
self.update_task(
TaskStatus.RUNNING,
message='Adding %s node(s) to %s(%s)' %
Expand Down Expand Up @@ -601,17 +594,9 @@ def create_nodes_thread(self):
TaskStatus.RUNNING,
message='Creating %s node(s) for %s(%s)' %
(self.body['node_count'], self.cluster_name, self.cluster_id))
new_nodes = add_nodes(
self.body['node_count'],
template,
TYPE_NODE,
self.config,
self.client_tenant,
org,
vdc,
vapp,
self.body,
wait=True)
new_nodes = add_nodes(self.body['node_count'], template, TYPE_NODE,
self.config, self.client_tenant, org, vdc,
vapp, self.body)
self.update_task(
TaskStatus.RUNNING,
message='Adding %s node(s) to %s(%s)' %
Expand Down
97 changes: 61 additions & 36 deletions container_service_extension/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import random
import re
import string
import time

Expand Down Expand Up @@ -97,16 +98,7 @@ def load_from_metadata(client, name=None, cluster_id=None):
return list(clusters_dict.values())


def add_nodes(qty,
template,
node_type,
config,
client,
org,
vdc,
vapp,
body,
wait=True):
def add_nodes(qty, template, node_type, config, client, org, vdc, vapp, body):
if qty < 1:
return None
specs = []
Expand All @@ -122,10 +114,7 @@ def add_nodes(qty,
if [ x$1=x"postcustomization" ];
then
""" # NOQA
cust_script_common = \
"""
echo "root:{password}" | chpasswd
""".format(password=template['admin_password']) # NOQA
cust_script_common = ''
if 'ssh_key' in body:
cust_script_common += \
"""
Expand Down Expand Up @@ -167,10 +156,9 @@ def add_nodes(qty,
else:
reconfigure_hw = False
task = vapp.add_vms(specs, power_on=not reconfigure_hw)
if wait:
# TODO(get details of the exception like not enough resources avail)
client.get_task_monitor().wait_for_status(task)
if wait and reconfigure_hw:
# TODO(get details of the exception like not enough resources avail)
client.get_task_monitor().wait_for_status(task)
if reconfigure_hw:
vapp.reload()
for spec in specs:
vm_resource = vapp.get_vm(spec['target_vm_name'])
Expand All @@ -184,8 +172,24 @@ def add_nodes(qty,
client.get_task_monitor().wait_for_status(task)
vm = VM(client, resource=vm_resource)
task = vm.power_on()
if wait:
client.get_task_monitor().wait_for_status(task)
client.get_task_monitor().wait_for_status(task)
password = source_vapp.get_admin_password(source_vm)
vapp.reload()
for spec in specs:
vm_resource = vapp.get_vm(spec['target_vm_name'])
script = \
"""#!/usr/bin/env bash
echo "root:{password}" | chpasswd
""".format(password=template['admin_password']) # NOQA
nodes = [vm_resource]
execute_script_in_nodes(
config,
vapp,
password,
script,
nodes,
check_tools=True,
wait=False)
return {'task': task, 'specs': specs}


Expand Down Expand Up @@ -313,11 +317,17 @@ def execute_script_in_nodes(config,
password,
script,
nodes,
check_tools=True):
check_tools=True,
wait=True):
all_results = []
for node in nodes:
if 'chpasswd' in script:
p = re.compile(':.*\"')
debug_script = p.sub(':***\"', script)
else:
debug_script = script
LOGGER.debug('will try to execute script on %s:\n%s' %
(node.get('name'), script))
(node.get('name'), debug_script))
vs = get_vsphere(config, vapp, node.get('name'))
vs.connect()
moid = vapp.get_vm_moid(node.get('name'))
Expand All @@ -327,20 +337,35 @@ def execute_script_in_nodes(config,
vs.wait_until_tools_ready(
vm, sleep=5, callback=wait_for_tools_ready_callback)
wait_until_ready_to_exec(vs, vm, password)
LOGGER.debug('about to execute script on %s' % node.get('name'))
result = vs.execute_script_in_guest(
vm,
'root',
password,
script,
target_file=None,
wait_for_completion=True,
wait_time=10,
get_output=True,
delete_script=True,
callback=wait_for_guest_execution_callback)
result_stdout = result[1].content.decode()
result_stderr = result[2].content.decode()
LOGGER.debug('about to execute script on %s, wait=%s' %
(node.get('name'), wait))
if wait:
result = vs.execute_script_in_guest(
vm,
'root',
password,
script,
target_file=None,
wait_for_completion=True,
wait_time=10,
get_output=True,
delete_script=True,
callback=wait_for_guest_execution_callback)
result_stdout = result[1].content.decode()
result_stderr = result[2].content.decode()
else:
result = vs.execute_script_in_guest(
vm,
'root',
password,
script,
target_file=None,
wait_for_completion=False,
get_output=False,
delete_script=False,
callback=wait_for_guest_execution_callback)
result_stdout = ''
result_stderr = ''
LOGGER.debug(result[0])
LOGGER.debug(result_stderr)
LOGGER.debug(result_stdout)
Expand Down
1 change: 1 addition & 0 deletions container_service_extension/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def run(self):
'%(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M:%S',
handlers=(handler, ))
logging.getLogger("pika").setLevel(logging.WARNING)

message = """
Container Service Extension for vCloud Director running
Expand Down
3 changes: 2 additions & 1 deletion container_service_extension/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def get_vsphere(config, vapp, vm_name):
break
cache[vm_id] = cache_item
else:
LOGGER.debug('retrieved from cache:\n%s' % cache[vm_id])
LOGGER.debug('vCenter retrieved from cache: %s / %s' %
(vm_id, cache[vm_id]['hostname']))

v = VSphere(cache[vm_id]['hostname'], cache[vm_id]['username'],
cache[vm_id]['password'], cache[vm_id]['port'])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ humanfriendly >= 4.8
pika >= 0.11.2
pyvcloud >= 19.1.1
vcd-cli >= 20.1.1
vsphere-guest-run >= 0.0.3
vsphere-guest-run >= 0.0.4
9 changes: 6 additions & 3 deletions scripts/cust-ubuntu-16.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

set -e

echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.default.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.lo.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'nameserver 8.8.8.8' >> /etc/resolvconf/resolv.conf.d/tail
resolvconf -u
systemctl restart networking.service

growpart /dev/sda 1
resize2fs /dev/sda1
growpart /dev/sda 1 || :
resize2fs /dev/sda1 || :

echo 'installing kuberentes'
echo 'installing kubernetes'
export DEBIAN_FRONTEND=noninteractive
apt-get -q update
apt-get -q install -y apt-transport-https ca-certificates curl software-properties-common
Expand Down
9 changes: 9 additions & 0 deletions tests/add-nodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

vcd cse cluster list

for i in `seq 1 3`;
do
echo cluster$i
vcd cse node create cluster$i --network $NETWORK --template $TEMPLATE --nodes 1
done
2 changes: 1 addition & 1 deletion tests/create-clusters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

for i in `seq 1 3`;
do
vcd --no-wait cse cluster create cluster$i --network $NETWORK --ssh-key ~/.ssh/id_rsa.pub
vcd --no-wait cse cluster create cluster$i --network $NETWORK --ssh-key ~/.ssh/id_rsa.pub --template $TEMPLATE
done

watch vcd task list running
9 changes: 9 additions & 0 deletions tests/info-clusters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

vcd cse cluster list

for i in `seq 1 3`;
do
echo cluster$i
vcd cse cluster info cluster$i
done

0 comments on commit 74f68f4

Please sign in to comment.