def test_003_fabricvlan_id_5000(): # type: uint # range: ["1-3967", "1-4029", "4048-4091", "4048-4093"] from ucscsdk.mometa.fabric.FabricVlan import FabricVlan vlan = FabricVlan(parent_mo_or_dn="parent_dn", name="my_vlan") vlan.id = 5000
def push_object(self, commit=True): if commit: self.logger(message="Pushing " + self._CONFIG_NAME + " configuration: " + self.name + ' (' + self.id + ')') else: self.logger(message="Adding to the handle " + self._CONFIG_NAME + " configuration: " + self.name + ' (' + self.id + ')' + ", waiting for a commit") if hasattr(self._parent, '_dn'): parent_mo = self._parent._dn else: self.logger(level="error", message="Impossible to find the parent dn of " + self._CONFIG_NAME + " : " + str(self.name)) return False mo_fabric_vlan = FabricVlan( parent_mo_or_dn=parent_mo + "/fabric/eth-estc", sharing=self.sharing_type, name=self.name, id=self.id, mcast_policy_name=self.multicast_policy_name, pub_nw_name=self.primary_vlan_name) self._handle.add_mo(mo=mo_fabric_vlan, modify_present=True) if self.org_permissions: for organization in self.org_permissions: complete_org_path = "" for part in organization.split("/"): if "org-" not in part: complete_org_path += "org-" complete_org_path += part + "/" complete_org_path = complete_org_path[: -1] # Remove the trailing "/" if not complete_org_path.startswith("org-root"): complete_org_path = "org-root/" + complete_org_path mo_fabric_vlan_req = FabricVlanReq( parent_mo_or_dn=complete_org_path, name=self.name) self._handle.add_mo(mo=mo_fabric_vlan_req, modify_present=True) if commit: if self.commit(detail=self.name + " (" + self.id + ")") != True: return False return True
def test_001_create_modify_vlan_global(): global vlan_id, vlan_name mo = FabricLanCloud(parent_mo_or_dn="domaingroup-root/fabric/lan", mode="end-host", vlan_compression="disabled", mac_aging="mode-default") dn = handle.query_dn("domaingroup-root/fabric/lan") mo = FabricVlan(parent_mo_or_dn="domaingroup-root/fabric/lan", name=vlan_name) handle.remove_mo(mo) handle.commit() handle.add_mo(mo) handle.commit() obj = handle.query_dn("domaingroup-root/fabric/lan/net-" + vlan_name) obj.id = vlan_id handle.set_mo(obj) handle.commit()
def main(): argument_spec = ucs_argument_spec argument_spec.update( name=dict(type='str', required=True), multicast_policy=dict(type='str', default=''), fabric=dict(type='str', default='common', choices=['common', 'A', 'B']), id=dict(type='str'), sharing=dict(type='str', default='none', choices=['none', 'primary', 'isolated', 'community']), native=dict(type='str', default='no', choices=['yes', 'no']), state=dict(type='str', default='present', choices=['present', 'absent']), domaingroup=dict(type='str', default='')) module = AnsibleModule( argument_spec, supports_check_mode=True, required_if=[ ['state', 'present', ['id']], ], ) ucs = UCSModule(module) err = False # UCSModule creation above verifies ucscsdk is present and exits on failure, so additional imports are done below. from ucscsdk.mometa.fabric.FabricLanCloud import FabricLanCloud from ucscsdk.mometa.fabric.FabricVlan import FabricVlan changed = False try: mo_exists = False props_match = False # dn is fabric/lan/net-<name> for common vlans or fabric/lan/[A or B]/net-<name> for A or B dn_base = '' if module.params['domaingroup']: dn_base = 'domaingroup-root/domaingroup-{}/fabric/lan'.format( module.params['domaingroup']) else: dn_base = 'domaingroup-root/fabric/lan' print(dn_base) if module.params['fabric'] != 'common': dn_base += '/' + module.params['fabric'] dn = dn_base + '/net-' + module.params['name'] mo = ucs.login_handle.query_dn(dn) if mo: mo_exists = True if module.params['state'] == 'absent': # mo must exist but all properties do not have to match if mo_exists: if not module.check_mode: ucs.login_handle.remove_mo(mo) ucs.login_handle.commit() changed = True else: if mo_exists: # check top-level mo props kwargs = dict(id=module.params['id']) kwargs['default_net'] = module.params['native'] kwargs['sharing'] = module.params['sharing'] kwargs['mcast_policy_name'] = module.params['multicast_policy'] if (mo.check_prop_match(**kwargs)): props_match = True if not props_match: if not module.check_mode: # create if mo does not already exist mo = FabricVlan( parent_mo_or_dn=dn_base, name=module.params['name'], id=module.params['id'], default_net=module.params['native'], sharing=module.params['sharing'], mcast_policy_name=module.params['multicast_policy'], ) ucs.login_handle.add_mo(mo, True) ucs.login_handle.commit() changed = True except Exception as e: err = True ucs.result['msg'] = "setup error: %s " % str(e) ucs.result['changed'] = changed if err: module.fail_json(**ucs.result) module.exit_json(**ucs.result)
def vlan_create(handle, name, id, sharing="none", vlan_type="lan", mcast_policy_name=None, compression_type="included", default_net="no", pub_nw_name=None, domain_group="root", **kwargs): """ Creates VLAN Args: handle (UcscHandle) name (string) : VLAN Name id (string): VLAN ID sharing (string) : Vlan sharing ["community", "isolated", "none", "primary"] vlan_type (string) : Type of Vlan ["lan", "appliance"] mcast_policy_name (string) : Multicast policy name compression_type (string) : ["excluded", "included"] default_net (string) : ["false", "no", "true", "yes"] pub_nw_name (string) : Name of primary vlan, applicable for isolated or community vlan domain_group (string) : Full domain group name **kwargs: Any additional key-value pair of managed object(MO)'s property and value, which are not part of regular args. This should be used for future version compatibility. Returns: FabricVlan: Managed Object Example: vlan_create(handle, "none", "vlan-lab", "123", "sample_mcast_policy", "included") """ from ucscsdk.mometa.fabric.FabricVlan import FabricVlan from ucscsdk.utils.ucscdomain import get_domain_group_dn domain_group_dn = get_domain_group_dn(handle, domain_group) if vlan_type != "lan" and vlan_type != "appliance": raise UcscOperationError("vlan_create", "Vlan Type %s does not exist" % vlan_type) vlan_obj_dn = domain_group_dn + "/fabric/lan" if vlan_type == "lan" else \ domain_group_dn + "/fabric/eth-estc" obj = handle.query_dn(vlan_obj_dn) if not obj: raise UcscOperationError( "vlan_create", "Fabric LAN cloud %s does not exist" % vlan_obj_dn) vlan = FabricVlan(parent_mo_or_dn=obj, sharing=sharing, name=name, id=id, mcast_policy_name=mcast_policy_name, default_net=default_net, pub_nw_name=pub_nw_name, compression_type=compression_type) vlan.set_prop_multiple(**kwargs) handle.add_mo(vlan, modify_present=True) handle.commit() return vlan