Recreate the pr

This commit is contained in:
C. R. Oldham 2016-01-12 13:42:06 -07:00
parent ba8d128025
commit 0da7a6d6d1
5 changed files with 226 additions and 3 deletions

View file

@ -1374,6 +1374,7 @@ class Minion(MinionBase):
log.debug('Refreshing modules. Notify={0}'.format(notify))
if hasattr(self, 'proxy'):
self.functions, self.returners, _ = self._load_modules(force_refresh, notify=notify, proxy=self.proxy)
self.functions['saltutil.sync_grains'](saltenv='base')
else:
self.functions, self.returners, _ = self._load_modules(force_refresh, notify=notify)
@ -2599,7 +2600,6 @@ class ProxyMinion(Minion):
# we talk to the device we are proxying for. So reload the grains
# functions here, and then force a grains sync.
self.opts['grains'] = salt.loader.grains(self.opts, force_refresh=True)
self.functions['saltutil.sync_grains'](saltenv='base')
# Check config 'add_proxymodule_to_opts' Remove this in Boron.
if self.opts['add_proxymodule_to_opts']:

View file

@ -36,6 +36,7 @@ try:
except ImportError:
pass
__proxyenabled__ = ['*']
# Define the module's virtual name
__virtualname__ = 'cmd'

View file

@ -23,6 +23,8 @@ from salt.ext.six.moves import map
log = logging.getLogger(__name__)
__proxyenabled__ = ['fx2']
try:
run_all = __salt__['cmd.run_all']
except NameError:
@ -1319,6 +1321,7 @@ def get_general(cfg_sec, cfg_var, host=None,
def bare_rac_cmd(cmd, host=None,
admin_username=None, admin_password=None):
ret = __execute_ret('{0}'.format(cmd),
host=host,
admin_username=admin_username,

View file

@ -180,7 +180,7 @@ except ImportError:
log = logging.getLogger(__name__)
__virtualname__ = 'vsphere'
__proxyenabled__ = 'esxi'
def __virtual__():
if not HAS_PYVMOMI:
@ -3224,6 +3224,19 @@ def vsan_enable(host, username, password, protocol=None, port=None, host_names=N
return ret
def get_dvs_portgroup_assignment(service_instance, host, dvs_name,
portgroup_name, host_names):
'''
:param service_instance: Reference to the vSphere server
:param dvs_name: Name of the DVS
:param portgroup_name: Portgroup to examine
:param host_names: Names of hosts
:return:
'''
host_refs = _check_hosts(service_instance, host, host_names)
def _check_hosts(service_instance, host, host_names):
'''
Helper function that checks to see if the host provided is a vCenter Server or
@ -3519,3 +3532,139 @@ def _set_syslog_config_helper(host, username, password, syslog_config, config_va
ret_dict.update({'syslog_restart': {'success': response['retcode'] == 0}})
return ret_dict
def add_host_to_vsphere(host, username, password, vsphere_protocol=None,
vsphere_port=None, host_names=None, host_username=None,
host_password=None):
'''
Add an ESX host to vSphere.
:param host: vSphere hostname or IP
:param username: Login to vSphere with this username
:param password: Login to vSphere with this password
:param vsphere_protocol:
:param vsphere_port:
:param host_names:
:param host_username:
:param host_password:
:return:
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
for host_name in host_names:
# try:
ret[host_name] = {}
ret[host_name].update({'status': False})
host_ref = _get_host_ref(service_instance, host, host_name)
def add_host_to_dvs(host, username, password, vmknic_name, vmnic_name,
dvs_name, portgroup_name, protocol=None, port=None,
host_names=None):
'''
Adds an ESXi host to a vSphere Distributed Virtual Switch
DOES NOT migrate the ESXi's physical and virtual NICs to the switch (yet)
(please don't remove the commented code)
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
dvs = salt.utils.vmware._get_dvs(service_instance, dvs_name)
target_portgroup = salt.utils.vmware._get_dvs_portgroup(dvs,
portgroup_name)
uplink_portgroup = salt.utils.vmware._get_dvs_uplink_portgroup(dvs,
'DSwitch-DVUplinks-34')
dvs_uuid = dvs.config.uuid
host_names = _check_hosts(service_instance, host, host_names)
ret = {}
for host_name in host_names:
# try:
ret[host_name] = {}
ret[host_name].update({'status': False,
'portgroup': portgroup_name,
'dvs': dvs_name})
host_ref = _get_host_ref(service_instance, host, host_name)
dvs_hostmember_config = vim.dvs.HostMember.ConfigInfo(
host=host_ref
)
dvs_hostmember = vim.dvs.HostMember(
config=dvs_hostmember_config
)
p_nics = salt.utils.vmware._get_pnics(host_ref)
p_nic = [x for x in p_nics if x.device == 'vmnic0']
v_nics = salt.utils.vmware._get_vnics(host_ref)
v_nic = [x for x in v_nics if x.device == vmknic_name]
v_nic_mgr = salt.utils.vmware._get_vnic_manager(host_ref)
dvs_pnic_spec = vim.dvs.HostMember.PnicSpec(
pnicDevice=vmnic_name,
uplinkPortgroupKey=uplink_portgroup.key
)
pnic_backing = vim.dvs.HostMember.PnicBacking(
pnicSpec=[dvs_pnic_spec]
)
dvs_hostmember_config_spec = vim.dvs.HostMember.ConfigSpec(
host=host_ref,
operation='add',
)
dvs_config = vim.DVSConfigSpec(
configVersion=dvs.config.configVersion,
host=[dvs_hostmember_config_spec])
task = dvs.ReconfigureDvs_Task(spec=dvs_config)
salt.utils.vmware.wait_for_task(task, host_name,
'Adding host to the DVS',
sleep_seconds=3)
ret[host_name].update({'status': True})
# # host_network_config.proxySwitch[0].spec.backing.pnicSpec = dvs_pnic_spec
#
# network_system = host_ref.configManager.networkSystem
#
# host_network_config = network_system.networkConfig
#
#
# orig_portgroup = network_system.networkInfo.portgroup[0]
# host_portgroup_config = []
# host_portgroup_config.append(vim.HostPortGroupConfig(
# changeOperation='remove',
# spec=orig_portgroup.spec
# ))
# # host_portgroup_config.append(vim.HostPortGroupConfig(
# # changeOperation='add',
# # spec=target_portgroup
# #
# # ))
# dvs_port_connection = vim.DistributedVirtualSwitchPortConnection(
# portgroupKey=target_portgroup.key, switchUuid=dvs_uuid
# )
# host_vnic_spec = vim.HostVirtualNicSpec(
# distributedVirtualPort=dvs_port_connection
# )
# host_vnic_config = vim.HostVirtualNicConfig(
# changeOperation='add',
# device=vmknic_name,
# portgroup=target_portgroup.key,
# spec=host_vnic_spec
# )
# host_network_config.proxySwitch[0].spec.backing = pnic_backing
# host_network_config.portgroup = host_portgroup_config
# host_network_config.vnic = [host_vnic_config]
# # host_network_config = vim.HostNetworkConfig(
# # portgroup=[host_portgroup_config],
# # vnic=[host_vnic_config]
# # )
# network_system.UpdateNetworkConfig(changeMode='modify',
# config=host_network_config)

View file

@ -196,7 +196,7 @@ def get_service_instance(host, username, password, protocol=None, port=None):
default_msg = 'Could not connect to host \'{0}\'. ' \
'Please check the debug log for more information.'.format(host)
try:
if (isinstance(exc, vim.fault.HostConnectFault) and '[SSL: CERTIFICATE_VERIFY_FAILED]' in exc.msg) or '[SSL: CERTIFICATE_VERIFY_FAILED]' in str(exc):
if (isinstance(exc, vim.fault.HostConnectFault) and 'certificate verify failed' in exc.msg.lower()) or 'certificate verify failed' in str(exc).lower():
import ssl
default_context = ssl._create_default_https_context
ssl._create_default_https_context = ssl._create_unverified_context
@ -236,6 +236,76 @@ def get_service_instance(host, username, password, protocol=None, port=None):
return service_instance
def _get_dvs(service_instance, dvs_name):
'''
Return a reference to a Distributed Virtual Switch object.
:param service_instance: PyVmomi service instance
:param dvs_name: Name of DVS to return
:return: A PyVmomi DVS object
'''
switches = list_dvs(service_instance)
if dvs_name in switches:
inventory = get_inventory(service_instance)
container = inventory.viewManager.CreateContainerView(inventory.rootFolder, [vim.DistributedVirtualSwitch], True)
for item in container.view:
if item.name == dvs_name:
return item
return None
def _get_pnics(host_reference):
'''
Helper function that returns a list of PhysicalNics and their information.
'''
return host_reference.config.network.pnic
def _get_vnics(host_reference):
'''
Helper function that returns a list of VirtualNics and their information.
'''
return host_reference.config.network.vnic
def _get_vnic_manager(host_reference):
'''
Helper function that returns a list of Virtual NicManagers
and their information.
'''
return host_reference.configManager.virtualNicManager
def _get_dvs_portgroup(dvs, portgroup_name):
'''
Return a portgroup object corresponding to the portgroup name on the dvs
:param dvs: DVS object
:param portgroup_name: Name of portgroup to return
:return: Portgroup object
'''
for portgroup in dvs.portgroup:
if portgroup.name == portgroup_name:
return portgroup
return None
def _get_dvs_uplink_portgroup(dvs, portgroup_name):
'''
Return a portgroup object corresponding to the portgroup name on the dvs
:param dvs: DVS object
:param portgroup_name: Name of portgroup to return
:return: Portgroup object
'''
for portgroup in dvs.portgroup:
if portgroup.name == portgroup_name:
return portgroup
return None
def get_inventory(service_instance):
'''
Return the inventory of a Service Instance Object.