Skip to content

Commit

Permalink
closes-bug:#1437854
Browse files Browse the repository at this point in the history
Adding support for multiple clusters during provisioning.

Change-Id: Ia89f6aeb6ba7d676b5fe1ddc54cdfb68c52f349d
  • Loading branch information
a committed Mar 30, 2015
1 parent 20c760a commit a87937d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
8 changes: 4 additions & 4 deletions fabfile/tasks/provision.py
Expand Up @@ -1949,8 +1949,8 @@ def add_esxi_to_vcenter(*args):
host_list = args
else:
host_list = esxi_info.keys()
(hosts, vms) = get_esxi_vms_and_hosts(esxi_info, vcenter_info, host_list)
provision_vcenter(vcenter_info, hosts, vms)
(hosts, clusters, vms) = get_esxi_vms_and_hosts(esxi_info, vcenter_info, host_list)
provision_vcenter(vcenter_info, hosts, clusters, vms)

@roles('build')
@task
Expand All @@ -1964,8 +1964,8 @@ def setup_vcenter():
print 'Error: esxi_hosts block is not defined in testbed file.Exiting'
return
host_list = esxi_info.keys()
(hosts, vms) = get_esxi_vms_and_hosts(esxi_info, vcenter_info, host_list)
provision_vcenter(vcenter_info, hosts, vms)
(hosts, clusters, vms) = get_esxi_vms_and_hosts(esxi_info, vcenter_info, host_list)
provision_vcenter(vcenter_info, hosts, clusters, vms)

@task
@roles('build')
Expand Down
26 changes: 19 additions & 7 deletions fabfile/tasks/vcenter_prov.py
Expand Up @@ -18,16 +18,18 @@ def __init__(self, vcenter_params):
self.dvportgroup_num_ports = vcenter_params['dvportgroup_num_ports']
self.hosts = vcenter_params['hosts']
self.vms = vcenter_params['vms']
self.clusters = vcenter_params['clusters']

try:

self.connect_to_vcenter()
datacenter = self.create_datacenter(dcname=self.datacenter_name)
cluster=self.create_cluster(self.cluster_name,datacenter)
for cluster_name in self.clusters:
cluster=self.create_cluster(cluster_name,datacenter)
network_folder = datacenter.networkFolder
for host_info in self.hosts:
self.add_host(cluster,host_info[0],host_info[3],host_info[1],host_info[2])
dvs=self.create_dvSwitch(self.service_instance, network_folder, cluster, self.dvswitch_name)
self.add_host(host_info[4],host_info[0],host_info[3],host_info[1],host_info[2])
dvs=self.create_dvSwitch(self.service_instance, network_folder, self.clusters, self.dvswitch_name)
self.add_dvPort_group(self.service_instance,dvs, self.dvportgroup_name)
for vm_name in self.vms:
self.add_vm_to_dvpg(self.service_instance,vm_name,dvs, self.dvportgroup_name)
Expand Down Expand Up @@ -56,16 +58,19 @@ def create_cluster(self, cluster_name, datacenter):
cluster = host_folder.CreateClusterEx(name=cluster_name, spec=cluster_spec)
return cluster

def add_host(self, cluster, hostname, sslthumbprint, username, password):
def add_host(self, cluster_name, hostname, sslthumbprint, username, password):
host = self.get_obj([self.pyVmomi.vim.HostSystem], hostname)
if host is not None:
print("host already exists")
return host
else:
if hostname is None:
raise ValueError("Missing value for name.")
cluster = self.get_obj([self.pyVmomi.vim.ClusterComputeResource], cluster_name)
if cluster is None:
raise ValueError("Missing value for cluster.")
error = 'Error - Cluster %s not found. Unable to add host %s' % (cluster_name, hostname)
raise ValueError(error)

try:
#openssl x509 -in /etc/vmware/ssl/rui.crt -fingerprint -sha1 -noout
hostspec = self.pyVmomi.vim.host.ConnectSpec(hostName=hostname,sslThumbprint=sslthumbprint,userName=username, password=password)
Expand Down Expand Up @@ -165,13 +170,14 @@ def add_vm_to_dvpg(self, si, vm_name, dv_switch, dv_port_name):
self.wait_for_task(task, si)
print "Succesfully added ContrailVM:%s to the DV port group" %(vm_name)

def create_dvSwitch(self, si, network_folder, cluster, dvs_name):
def create_dvSwitch(self, si, network_folder, clusters, dvs_name):
dvs = self.get_obj([self.pyVmomi.vim.DistributedVirtualSwitch], dvs_name)
if dvs is not None:
print("dvswitch already exists")
return dvs
else:
pnic_specs = []
host_list = []
dvs_host_configs = []
uplink_port_names = []
pvlan_configs = []
Expand Down Expand Up @@ -202,7 +208,13 @@ def create_dvSwitch(self, si, network_folder, cluster, dvs_name):

dvs_config_spec.name = dvs_name
dvs_config_spec.uplinkPortPolicy = self.pyVmomi.vim.DistributedVirtualSwitch.NameArrayUplinkPortPolicy()
hosts = cluster.host
for cluster_name in clusters:
cluster = self.get_obj([self.pyVmomi.vim.ClusterComputeResource], cluster_name)
host_list.append(cluster.host)
hosts = []
for mo in host_list:
for host in mo:
hosts.append(host)
for x in range(len(hosts)):
uplink_port_names.append("dvUplink%d" % x)

Expand Down
3 changes: 2 additions & 1 deletion fabfile/tasks/vmware.py
Expand Up @@ -186,7 +186,7 @@ def _template_substitute_write(template, vals, filename):
#end _template_substitute_write

@task
def provision_vcenter(vcenter_info, hosts, vms):
def provision_vcenter(vcenter_info, hosts, clusters, vms):
apt_install(['contrail-vmware-utils'])
vcenter_params = {}
vcenter_params['server'] = vcenter_info['server']
Expand All @@ -201,6 +201,7 @@ def provision_vcenter(vcenter_info, hosts, vms):

vcenter_params['hosts'] = hosts
vcenter_params['vms'] = vms
vcenter_params['clusters'] = clusters

Vcenter(vcenter_params)
#end provision_vcenter
4 changes: 3 additions & 1 deletion fabfile/testbeds/testbed_multibox_example.py
Expand Up @@ -371,7 +371,7 @@
# 'password': 'Contrail123!',
# 'auth': 'https',
# 'datacenter': 'kd_dc',
# 'cluster': 'kd_cluster',
# 'cluster': ['kd_cluster_1','kd_cluster_2'],
# 'dv_switch': { 'dv_switch_name': 'kd_dvswitch',
# },
# 'dv_port_group': { 'dv_portgroup_name': 'kd_dvportgroup',
Expand All @@ -396,6 +396,7 @@
# uplinck_nic: the nic used for underlay
# optional, defaults to None
# data_store: the datastore on esxi where the vmdk is copied to
# cluster: name of the cluster to which this esxi is added
# contrail_vm information:
# mac: the virtual mac address for the contrail vm
# host: the contrail_vm ip in the form of 'user@contrailvm_ip'
Expand All @@ -411,6 +412,7 @@
# 'username': 'root',
# 'password': 'c0ntrail123',
# 'datastore': "/vmfs/volumes/ds1",
# 'cluster': "kd_cluster_1",
# 'contrail_vm': {
# 'mac': "00:50:56:05:ba:ba",
# 'host': "root@2.2.2.2",
Expand Down
6 changes: 4 additions & 2 deletions fabfile/utils/cluster.py
Expand Up @@ -62,20 +62,22 @@ def get_esxi_ssl_thumbprint(esxi_data):
def get_esxi_vms_and_hosts(esxi_info, vcenter_info, host_list):
hosts = []
vms = []
clusters = []
for host in host_list:
with settings(host=host):
if host in esxi_info.keys():
esxi_data = esxi_info[host]
vm_name = "ContrailVM"
ssl_thumbprint = get_esxi_ssl_thumbprint(esxi_data)
esx_list=esxi_data['ip'],esxi_data['username'],esxi_data['password'],ssl_thumbprint
esx_list=esxi_data['ip'],esxi_data['username'],esxi_data['password'],ssl_thumbprint,esxi_data['cluster']
hosts.append(esx_list)
modified_vm_name = vm_name+"-"+vcenter_info['datacenter']+"-"+esxi_data['ip']
vms.append(modified_vm_name)
else:
print 'Info: esxi_hosts block does not have the esxi host.Exiting'
return
return (hosts,vms)
clusters = vcenter_info['cluster']
return (hosts,clusters,vms)

def get_nodes_to_upgrade_pkg(package, os_type, *args, **kwargs):
"""get the list of nodes in which th given package needs to be upgraded"""
Expand Down

0 comments on commit a87937d

Please sign in to comment.