Ejemplo n.º 1
0
    def run(self, name, operator_permissions, group_permissions, **kwargs):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        permission_map = {'ro': '1', 'rw': '2', 'rwa': '3'}

        self.ipam.login(auth=(self.api_username, self.api_password))

        sections_api = SectionsApi(phpipam=self.ipam)

        if kwargs['master_section']:
            kwargs['master_section_id'] = get_section_id(
                ipam=self.ipam, name=kwargs['master_section'])

        permissions = {}
        permissions['2'] = permission_map[operator_permissions]
        permissions['3'] = permission_map[group_permissions]

        kwargs['show_vlan'] = int(kwargs['show_vlan'])
        kwargs['show_vrf'] = int(kwargs['show_vrf'])
        kwargs['strict_mode'] = int(kwargs['strict_mode'])

        new_section = sections_api.add_section(
            name=name, permissions=json.dumps(permissions), **kwargs)

        self.ipam.logout()

        return new_section
Ejemplo n.º 2
0
    def run(self, subnet_cidr, **kwargs):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        sect_id = get_section_id(ipam=self.ipam, name=kwargs['section'])

        subnet_id = get_subnet_id(
            ipam=self.ipam, cidr=subnet_cidr, section_id=sect_id)

        kwargs['tag_id'] = get_tag_id(ipam=self.ipam, name=kwargs['tag'])

        if kwargs['device']:
            kwargs['device_id'] = get_tools_device_id(
                ipam=self.ipam, name=kwargs['device'])

        addresses_api = AddressesApi(phpipam=self.ipam)

        new_address = addresses_api.add_address_first_free(
            subnet_id=subnet_id, **kwargs)

        self.ipam.logout()

        return new_address
Ejemplo n.º 3
0
    def run(self, section):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        sections_api = SectionsApi(phpipam=self.ipam)

        sect_id = get_section_id(ipam=self.ipam, name=section)

        subnetlist = sections_api.list_section_subnets(section_id=sect_id)

        self.ipam.logout()

        return subnetlist
Ejemplo n.º 4
0
    def run(self, name):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        sections_api = SectionsApi(phpipam=self.ipam)

        sect_id = get_section_id(ipam=self.ipam, name=name)

        delete_result = sections_api.del_section(section_id=sect_id)

        self.ipam.logout()

        return delete_result
Ejemplo n.º 5
0
    def run(self, section, subnet_cidr):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        subnets_api = SubnetsApi(phpipam=self.ipam)

        sect_id = get_section_id(ipam=self.ipam, name=section)

        sub_id = get_subnet_id(
            ipam=self.ipam, cidr=subnet_cidr, section_id=sect_id)

        addresslist = subnets_api.list_subnet_addresses(subnet_id=sub_id)

        self.ipam.logout()

        return addresslist
Ejemplo n.º 6
0
    def run(self, section, subnet_cidr, ip_addr):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        addresses_api = AddressesApi(phpipam=self.ipam)

        sect_id = get_section_id(ipam=self.ipam, name=section)

        subnet_id = get_subnet_id(ipam=self.ipam,
                                  cidr=subnet_cidr,
                                  section_id=sect_id)

        addr_id = get_address_id(ipam=self.ipam,
                                 ip_addr=ip_addr,
                                 subnet_id=subnet_id)

        delete_result = addresses_api.del_address(address_id=addr_id)

        self.ipam.logout()

        return delete_result
Ejemplo n.º 7
0
    def run(self, hostname, ip_addr, devicetype, **kwargs):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        type_id = get_tools_devicetype_id(ipam=self.ipam, name=devicetype)

        if kwargs['location']:
            kwargs['location_id'] = get_tools_location_id(
                ipam=self.ipam, name=kwargs['location'])

        if kwargs['rack']:
            kwargs['rack_id'] = get_tools_rack_id(
                ipam=self.ipam, name=kwargs['rack'])

        if kwargs['sections']:
            sect_names = kwargs['sections'].split(';')
            section_ids = []

            for sect_name in sect_names:
                section_ids.append(
                    get_section_id(ipam=self.ipam, name=sect_name))

            kwargs['sections'] = ';'.join(section_ids)

        devices_api = ToolsDevicesApi(phpipam=self.ipam)

        new_device = devices_api.add_tools_device(
            hostname=hostname,
            ip_addr=ip_addr,
            type_id=type_id,
            **kwargs)

        self.ipam.logout()

        return new_device
Ejemplo n.º 8
0
    def run(self, name, **kwargs):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        self.ipam.login(auth=(self.api_username, self.api_password))

        if kwargs['sections'] is not None:
            sect_names = kwargs['sections'].split(';')

            section_ids = []

            for sect_name in sect_names:
                section_ids.append(
                    get_section_id(ipam=self.ipam, name=sect_name))

            kwargs['sections'] = ';'.join(section_ids)

        vrfs_api = VRFsApi(phpipam=self.ipam)

        new_vrf = vrfs_api.add_vrf(name=name, **kwargs)

        self.ipam.logout()

        return new_vrf
Ejemplo n.º 9
0
    def run(self, master_subnet, mask, operator_permissions, group_permissions,
            **kwargs):
        """ Stackstorm Run Method  """
        warnings.filterwarnings('ignore')

        permission_map = {'ro': '1', 'rw': '2', 'rwa': '3'}
        self.ipam.login(auth=(self.api_username, self.api_password))

        subnets_api = SubnetsApi(phpipam=self.ipam)

        kwargs['section_id'] = get_section_id(ipam=self.ipam,
                                              name=kwargs['section'])

        master_subnet_id = get_subnet_id(ipam=self.ipam,
                                         cidr=master_subnet,
                                         section_id=kwargs['section_id'])

        if kwargs['vlan']:
            if kwargs['l2domain']:
                raise ValueError('If VLAN number is specified then ' +
                                 'Layer 2 domain must also be set!')

            l2dom_id = get_l2domain_id(ipam=self.ipam, name=kwargs['l2domain'])

            kwargs['vlan_id'] = get_vlan_id(ipam=self.ipam,
                                            number=kwargs['vlan'],
                                            l2domain_id=l2dom_id)

        if kwargs['device']:
            kwargs['device_id'] = get_tools_device_id(ipam=self.ipam,
                                                      name=kwargs['device'])

        if kwargs['threshold']:
            if kwargs['threshold'] < 1 or kwargs['threshold'] > 100:
                raise ValueError('Threshold should be between 1 and 100')

        if kwargs['vrf']:
            kwargs['vrf_id'] = get_vrf_id(ipam=self.ipam, name=kwargs['vrf'])

        if kwargs['location']:
            kwargs['location_id'] = get_tools_location_id(
                ipam=self.ipam, name=kwargs['location'])

        if ((kwargs['ping_subnet'] or kwargs['discover_subnet']) and
            (kwargs['scan_agent'] is None or kwargs['scan_agent'] == '0')):
            kwargs['scan_agent_id'] = '1'

        permissions = {}

        permissions['2'] = permission_map[operator_permissions]
        permissions['3'] = permission_map[group_permissions]

        kwargs['show_name'] = int(kwargs['show_name'])
        kwargs['ping_subnet'] = int(kwargs['ping_subnet'])
        kwargs['discover_subnet'] = int(kwargs['discover_subnet'])
        kwargs['full'] = int(kwargs['full'])

        new_subnet = subnets_api.add_subnet_first_free(
            subnet_id=master_subnet_id,
            mask=mask,
            permissions=json.dumps(permissions),
            **kwargs)

        self.ipam.logout()

        return new_subnet