Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant use "." symbols in site name #95

Closed
TawR1024 opened this issue Feb 13, 2020 · 4 comments · Fixed by #101
Closed

Cant use "." symbols in site name #95

TawR1024 opened this issue Feb 13, 2020 · 4 comments · Fixed by #101
Labels
bug Something isn't working Discussion PR Submitted
Milestone

Comments

@TawR1024
Copy link
Contributor

ISSUE TYPE
  • Bug Report
  • Feature Idea
SUMMARY

Cant use "." symbols in site name

STEPS TO REPRODUCE
- name: "Create Site"
  connection: local
  hosts: localhost
  collections:
   - netbox_community.ansible_modules
  gather_facts: False
  tasks:
    - name: Create site within Netbox with only required information
      netbox_site:
        netbox_url: "{{ url }}"
        netbox_token: "{{ token }}"
        data:
          name: test-1.one.two.org
          tenant: VPC
        state: present
EXPECTED RESULTS

expected slug is test_1_one_two_org

ACTUAL RESULTS

Got an error

But have message:
`"msg": "{\"slug\":[\"Enter a valid \\\"slug\\\" consisting of letters, numbers, underscores or hyphens.\"]}",`

To fix this bug:

def _to_slug(self, value):
        """
        :returns slug (str): Slugified value
        :params value (str): Value that needs to be changed to slug format
        """
        if value is None:
            return value
        elif isinstance(value, int):
            return value
        if " " in value:
            value = value.replace(" ", "_")
        if "." in value:
            value = value.replace(".", "_")
        value = value.lower()
@Shm013
Copy link

Shm013 commented Feb 13, 2020

But how about replacing ,;:[]©¶ÂÆ ?
Maybe take to_slug function from netbox?

@FragmentedPacket
Copy link
Contributor

Thanks for reporting this. After doing some research, it appears I've been converting the names incorrectly as to how Netbox converts things to slug. It converts spaces and . to hyphens and removes any characters that wouldn't pass the validator.

@Shm013 I don't see the to_slug function. Could you point me to it?

I was pointed to JS that appears to take care of the slugify function.

https://github.com/netbox-community/netbox/blob/develop/netbox/project-static/js/forms.js#L36

I believe I'm going to move forward with implementing that into the _to_slug unless there are any objections, but my reasoning for doing this is to minimalize the data manipulation in these models and adhere as close as possible to Netbox.

@FragmentedPacket
Copy link
Contributor

Please check the PR and let me know if you have any feedback.

@TawR1024
Copy link
Contributor Author

Hey, thanks for the quick bug fix.
From now it works perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Discussion PR Submitted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants