netbox-sync icon indicating copy to clipboard operation
netbox-sync copied to clipboard

vm_tenant_relation

Open akurach opened this issue 2 years ago • 11 comments

issue with assigning vm with Tenant if vm_tenant_relation is exist

INFO: Tenant 'NAME' attribute 'slug' changed from 'u0002-slug' to '-'

So if tenant already exists - its rewrite slug to '-'

akurach avatar Jun 28 '22 14:06 akurach

Hi,

It would be helpful to get some more information. How does the config look like? can you run the tool with -l DEBUG2 and post the output around the issue here?

The tenant exists in NetBox? How does it look like?

bb-Ricardo avatar Jun 29 '22 07:06 bb-Ricardo

Here is existing Tenant

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 84,
      "url": "https://netbox.site/api/tenancy/tenants/84/",
      "display": "test",
      "name": "test",
      "slug": "test-sync",
      "group": null,
      "description": "",
      "comments": "",
      "tags": [
        {
          "id": 2,
          "url": "https://netbox.site/api/extras/tags/2/",
          "display": "Development",
          "name": "Development",
          "slug": "development",
          "color": "9e9e9e"
        }
      ],
      "custom_fields": {
        "documentation": null,
        "git": null
      },
      "created": "2022-06-30T13:20:02.496277Z",
      "last_updated": "2022-06-30T13:20:02.496307Z",
      "circuit_count": 0,
      "device_count": 0,
      "ipaddress_count": 0,
      "prefix_count": 0,
      "rack_count": 0,
      "site_count": 0,
      "virtualmachine_count": 0,
      "vlan_count": 0,
      "vrf_count": 0,
      "cluster_count": 0
    }
  ]
}

Logs from DEBUG2:

INFO: Updating NetBox 'tenant' object 'test' with data: {'slug': 'test', 'tags': [{'name': 'NetBox-synced'}, {'name': 'Source: i.local'}, {'name': 'Development'}]}
2022-06-30 16:23:57,125 - DEBUG2: Sending PATCH to 'https://netbox.site/api/tenancy/tenants/84/' with data 'b'{"slug": "test", "tags": [{"name": "NetBox-synced"}, {"name": "Source: i.local"}, {"name": "Development"}]}''.

Tenant after sync:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 84,
      "url": "https://netbox.site/api/tenancy/tenants/84/",
      "display": "test",
      "name": "test",
      "slug": "test",
      "group": null,
      "description": "",
      "comments": "",
      "tags": [
        {
          "id": 2,
          "url": "https://netbox.site/api/extras/tags/2/",
          "display": "Development",
          "name": "Development",
          "slug": "development",
          "color": "9e9e9e"
        },
        {
          "id": 16,
          "url": "https://netbox.site/api/extras/tags/16/",
          "display": "NetBox-synced",
          "name": "NetBox-synced",
          "slug": "netbox-synced",
          "color": "9e9e9e"
        },
        {
          "id": 20,
          "url": "https://netbox.site/api/extras/tags/20/",
          "display": "Source: i.local",
          "name": "Source: i.local",
          "slug": "source-i-local",
          "color": "9e9e9e"
        }
      ],
      "custom_fields": {
        "documentation": null,
        "git": null
      },
      "created": "2022-06-30T13:20:02.496277Z",
      "last_updated": "2022-06-30T13:23:57.289743Z",
      "circuit_count": 0,
      "device_count": 0,
      "ipaddress_count": 0,
      "prefix_count": 0,
      "rack_count": 0,
      "site_count": 0,
      "virtualmachine_count": 6,
      "vlan_count": 0,
      "vrf_count": 0,
      "cluster_count": 0
    }
  ]
}

Config string:

vm_tenant_relation = u* = test

akurach avatar Jun 30 '22 13:06 akurach

Ok, looks good. Any reason why you changed the tenant slug in NetBox?

Otherwise the update seemed to work fine.

bb-Ricardo avatar Jun 30 '22 13:06 bb-Ricardo

thats the main issue - slug was changed by sync update. It sent PATH with slug = name

Updating NetBox 'tenant' object 'test' with data: {'slug': 'test',

akurach avatar Jun 30 '22 13:06 akurach

Can you explain why this causes an issue?

bb-Ricardo avatar Jun 30 '22 13:06 bb-Ricardo

If question is about why I've created Tenant by hands:

I've got ansible playbook that creates all the tenants, and in our env we have different names and slug, including cyrillic names.

If talk more globally about our case: tenant name = Information System Short Name ( usually cyrillic) tenant slug = Infornation System Code ( from our register)

akurach avatar Jun 30 '22 13:06 akurach

Alright. I have to come up with a general solution to solve this. Currently the slug is created on demand from the name.

Will look into it next week.

bb-Ricardo avatar Jun 30 '22 13:06 bb-Ricardo

Example:

Tenant Name: Simple_IS Tenant Slug: u001-simpl

after sync slug will be 'simple-is'

Example2: Tenant Name: Простая ИС Tenant slug: u002-simpl2

after sync slug will be '-'

akurach avatar Jun 30 '22 13:06 akurach

True, it is pretty ignorant to assume objects are named using roman letters.

bb-Ricardo avatar Jun 30 '22 13:06 bb-Ricardo

So expected behaviour for me look like If tenant exists - just assosiate VM with it, do not rewrite tenant if tenant not exists - create tenant with autoslug and assosiate vm with tenant

additional idea: add to settings slug? so it will look like vm_tenant_relation = vmregex = [name,slug] ,...

OR use slug in config insted of name?

akurach avatar Jun 30 '22 13:06 akurach

True, it is pretty ignorant to assume objects are named using roman letters.

Agree, but Managers wants to see 'TRUE NAMES' in RU. Nevertheless the case is not about Cyrilic symbols :)

akurach avatar Jun 30 '22 14:06 akurach

Hi,

Sorry it took quite a while. I just pushed a new commit to the development branch. Would you mind to test it and see if this fixes your issue?

Thank you

bb-Ricardo avatar Aug 25 '22 07:08 bb-Ricardo