def add_port_group(name, vlan_id, vswitch, network_system, vCenterserver, username, password): s = VIServer() s.connect(vCenterserver, username, password) request = VI.AddPortGroupRequestMsg() _this = request.new__this(network_system) _this.set_attribute_type(network_system.get_attribute_type()) request.set_element__this(_this) portgrp = request.new_portgrp() portgrp.set_element_name(name) portgrp.set_element_vlanId(vlan_id) portgrp.set_element_vswitchName(vswitch) portgrp.set_element_policy(portgrp.new_policy()) request.set_element_portgrp(portgrp) s._proxy.AddPortGroup(request)
def create_portgroup_in_host(vCenterserver, username, password, host, pgname, vswitchname, vlan_id): resp = "succeeded" con = None try: con = vs_connect(vCenterserver, username, password) hostmor = [k for k, v in con.get_hosts().items() if v == host][0] prop = VIProperty(con, hostmor) network_system = prop.configManager.networkSystem._obj request = VI.AddPortGroupRequestMsg() _this = request.new__this(network_system) _this.set_attribute_type(network_system.get_attribute_type()) request.set_element__this(_this) portgrp = request.new_portgrp() portgrp.set_element_name(pgname) portgrp.set_element_vlanId(int(vlan_id)) portgrp.set_element_vswitchName(vswitchname) portgrp.set_element_policy(portgrp.new_policy()) request.set_element_portgrp(portgrp) con._proxy.AddPortGroup(request) except Exception, error: resp = str_remove_specialchars(error)