def setUpTestData(cls): ClusterGroup.objects.bulk_create([ ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ]) tags = create_tags('Alpha', 'Bravo', 'Charlie') cls.form_data = { 'name': 'Cluster Group X', 'slug': 'cluster-group-x', 'description': 'A new cluster group', 'tags': [t.pk for t in tags], } cls.csv_data = ( "name,slug,description", "Cluster Group 4,cluster-group-4,Fourth cluster group", "Cluster Group 5,cluster-group-5,Fifth cluster group", "Cluster Group 6,cluster-group-6,Sixth cluster group", ) cls.bulk_edit_data = { 'description': 'New description', }
def setUpTestData(cls): sites = ( Site(name='Site 1', slug='site-1'), Site(name='Site 2', slug='site-2'), ) Site.objects.bulk_create(sites) clustergroups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ) ClusterGroup.objects.bulk_create(clustergroups) clustertypes = ( ClusterType(name='Cluster Type 1', slug='cluster-type-1'), ClusterType(name='Cluster Type 2', slug='cluster-type-2'), ) ClusterType.objects.bulk_create(clustertypes) Cluster.objects.bulk_create([ Cluster(name='Cluster 1', group=clustergroups[0], type=clustertypes[0], site=sites[0]), Cluster(name='Cluster 2', group=clustergroups[0], type=clustertypes[0], site=sites[0]), Cluster(name='Cluster 3', group=clustergroups[0], type=clustertypes[0], site=sites[0]), ]) cls.form_data = { 'name': 'Cluster X', 'group': clustergroups[1].pk, 'type': clustertypes[1].pk, 'tenant': None, 'site': sites[1].pk, 'comments': 'Some comments', 'tags': 'Alpha,Bravo,Charlie', } cls.csv_data = ( "name,type", "Cluster 4,Cluster Type 1", "Cluster 5,Cluster Type 1", "Cluster 6,Cluster Type 1", ) cls.bulk_edit_data = { 'group': clustergroups[1].pk, 'type': clustertypes[1].pk, 'tenant': None, 'site': sites[1].pk, 'comments': 'New comments', }
def setUpTestData(cls): cluster_Groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-type-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-type-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-type-3'), ) ClusterGroup.objects.bulk_create(cluster_Groups)
def setUpTestData(cls): cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1', description='A'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2', description='B'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3', description='C'), ) ClusterGroup.objects.bulk_create(cluster_groups)
def setUp(self): self.client = Client() ClusterGroup.objects.bulk_create([ ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ])
def setUp(self): user = create_test_user( permissions=['virtualization.view_clustergroup']) self.client = Client() self.client.force_login(user) ClusterGroup.objects.bulk_create([ ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ])
def setUpTestData(cls): cluster_types = ( ClusterType(name='Cluster Type 1', slug='cluster-type-1'), ClusterType(name='Cluster Type 2', slug='cluster-type-2'), ClusterType(name='Cluster Type 3', slug='cluster-type-3'), ) ClusterType.objects.bulk_create(cluster_types) cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ) ClusterGroup.objects.bulk_create(cluster_groups) regions = ( Region(name='Test Region 1', slug='test-region-1'), Region(name='Test Region 2', slug='test-region-2'), Region(name='Test Region 3', slug='test-region-3'), ) # Can't use bulk_create for models with MPTT fields for r in regions: r.save() sites = ( Site(name='Test Site 1', slug='test-site-1', region=regions[0]), Site(name='Test Site 2', slug='test-site-2', region=regions[1]), Site(name='Test Site 3', slug='test-site-3', region=regions[2]), ) Site.objects.bulk_create(sites) tenant_groups = ( TenantGroup(name='Tenant group 1', slug='tenant-group-1'), TenantGroup(name='Tenant group 2', slug='tenant-group-2'), TenantGroup(name='Tenant group 3', slug='tenant-group-3'), ) for tenantgroup in tenant_groups: tenantgroup.save() tenants = ( Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]), Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1]), Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]), ) Tenant.objects.bulk_create(tenants) clusters = ( Cluster(name='Cluster 1', type=cluster_types[0], group=cluster_groups[0], site=sites[0], tenant=tenants[0]), Cluster(name='Cluster 2', type=cluster_types[1], group=cluster_groups[1], site=sites[1], tenant=tenants[1]), Cluster(name='Cluster 3', type=cluster_types[2], group=cluster_groups[2], site=sites[2], tenant=tenants[2]), ) Cluster.objects.bulk_create(clusters)
def setUp(self): self.client = Client() clustergroup = ClusterGroup(name='Cluster Group 1', slug='cluster-group-1') clustergroup.save() clustertype = ClusterType(name='Cluster Type 1', slug='cluster-type-1') clustertype.save() Cluster.objects.bulk_create([ Cluster(name='Cluster 1', group=clustergroup, type=clustertype), Cluster(name='Cluster 2', group=clustergroup, type=clustertype), Cluster(name='Cluster 3', group=clustergroup, type=clustertype), ])
def setUp(self): self.client = Client() clustergroup = ClusterGroup(name='Cluster Group 1', slug='cluster-group-1') clustergroup.save() clustertype = ClusterType(name='Cluster Type 1', slug='cluster-type-1') clustertype.save() Cluster.objects.bulk_create([ Cluster(name='Cluster 1', group=clustergroup, type=clustertype), Cluster(name='Cluster 2', group=clustergroup, type=clustertype), Cluster(name='Cluster 3', group=clustergroup, type=clustertype), ])
def setUp(self): user = create_test_user(permissions=['virtualization.view_cluster']) self.client = Client() self.client.force_login(user) clustergroup = ClusterGroup(name='Cluster Group 1', slug='cluster-group-1') clustergroup.save() clustertype = ClusterType(name='Cluster Type 1', slug='cluster-type-1') clustertype.save() Cluster.objects.bulk_create([ Cluster(name='Cluster 1', group=clustergroup, type=clustertype), Cluster(name='Cluster 2', group=clustergroup, type=clustertype), Cluster(name='Cluster 3', group=clustergroup, type=clustertype), ])
def setUpTestData(cls): cluster_types = ( ClusterType(name='Cluster Type 1', slug='cluster-type-1'), ClusterType(name='Cluster Type 2', slug='cluster-type-2'), ) ClusterType.objects.bulk_create(cluster_types) cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ) ClusterGroup.objects.bulk_create(cluster_groups) clusters = ( Cluster(name='Cluster 1', type=cluster_types[0], group=cluster_groups[0]), Cluster(name='Cluster 2', type=cluster_types[0], group=cluster_groups[0]), Cluster(name='Cluster 3', type=cluster_types[0], group=cluster_groups[0]), ) Cluster.objects.bulk_create(clusters) cls.create_data = [ { 'name': 'Cluster 4', 'type': cluster_types[1].pk, 'group': cluster_groups[1].pk, }, { 'name': 'Cluster 5', 'type': cluster_types[1].pk, 'group': cluster_groups[1].pk, }, { 'name': 'Cluster 6', 'type': cluster_types[1].pk, 'group': cluster_groups[1].pk, }, ]
def setUpTestData(cls): ClusterGroup.objects.bulk_create([ ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ]) cls.form_data = { 'name': 'Cluster Group X', 'slug': 'cluster-group-x', } cls.csv_data = ( "name,slug", "Cluster Group 4,cluster-group-4", "Cluster Group 5,cluster-group-5", "Cluster Group 6,cluster-group-6", )
def setUpTestData(cls): ClusterGroup.objects.bulk_create([ ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ]) cls.form_data = { 'name': 'Cluster Group X', 'slug': 'cluster-group-x', 'description': 'A new cluster group', } cls.csv_data = ( "name,slug,description", "Cluster Group 4,cluster-group-4,Fourth cluster group", "Cluster Group 5,cluster-group-5,Fifth cluster group", "Cluster Group 6,cluster-group-6,Sixth cluster group", )
def setUpTestData(cls): cluster_types = ( ClusterType(name='Cluster Type 1', slug='cluster-type-1'), ClusterType(name='Cluster Type 2', slug='cluster-type-2'), ClusterType(name='Cluster Type 3', slug='cluster-type-3'), ) ClusterType.objects.bulk_create(cluster_types) cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ) ClusterGroup.objects.bulk_create(cluster_groups) regions = ( Region(name='Test Region 1', slug='test-region-1'), Region(name='Test Region 2', slug='test-region-2'), Region(name='Test Region 3', slug='test-region-3'), ) for r in regions: r.save() site_groups = ( SiteGroup(name='Site Group 1', slug='site-group-1'), SiteGroup(name='Site Group 2', slug='site-group-2'), SiteGroup(name='Site Group 3', slug='site-group-3'), ) for site_group in site_groups: site_group.save() sites = ( Site(name='Test Site 1', slug='test-site-1', region=regions[0], group=site_groups[0]), Site(name='Test Site 2', slug='test-site-2', region=regions[1], group=site_groups[1]), Site(name='Test Site 3', slug='test-site-3', region=regions[2], group=site_groups[2]), ) Site.objects.bulk_create(sites) clusters = ( Cluster(name='Cluster 1', type=cluster_types[0], group=cluster_groups[0], site=sites[0]), Cluster(name='Cluster 2', type=cluster_types[1], group=cluster_groups[1], site=sites[1]), Cluster(name='Cluster 3', type=cluster_types[2], group=cluster_groups[2], site=sites[2]), ) Cluster.objects.bulk_create(clusters) platforms = ( Platform(name='Platform 1', slug='platform-1'), Platform(name='Platform 2', slug='platform-2'), Platform(name='Platform 3', slug='platform-3'), ) Platform.objects.bulk_create(platforms) roles = ( DeviceRole(name='Device Role 1', slug='device-role-1'), DeviceRole(name='Device Role 2', slug='device-role-2'), DeviceRole(name='Device Role 3', slug='device-role-3'), ) DeviceRole.objects.bulk_create(roles) tenant_groups = ( TenantGroup(name='Tenant group 1', slug='tenant-group-1'), TenantGroup(name='Tenant group 2', slug='tenant-group-2'), TenantGroup(name='Tenant group 3', slug='tenant-group-3'), ) for tenantgroup in tenant_groups: tenantgroup.save() tenants = ( Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]), Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1]), Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]), ) Tenant.objects.bulk_create(tenants) vms = ( VirtualMachine(name='Virtual Machine 1', cluster=clusters[0], platform=platforms[0], role=roles[0], tenant=tenants[0], status=VirtualMachineStatusChoices.STATUS_ACTIVE, vcpus=1, memory=1, disk=1, local_context_data={"foo": 123}), VirtualMachine(name='Virtual Machine 2', cluster=clusters[1], platform=platforms[1], role=roles[1], tenant=tenants[1], status=VirtualMachineStatusChoices.STATUS_STAGED, vcpus=2, memory=2, disk=2), VirtualMachine(name='Virtual Machine 3', cluster=clusters[2], platform=platforms[2], role=roles[2], tenant=tenants[2], status=VirtualMachineStatusChoices.STATUS_OFFLINE, vcpus=3, memory=3, disk=3), ) VirtualMachine.objects.bulk_create(vms) interfaces = ( VMInterface(virtual_machine=vms[0], name='Interface 1', mac_address='00-00-00-00-00-01'), VMInterface(virtual_machine=vms[1], name='Interface 2', mac_address='00-00-00-00-00-02'), VMInterface(virtual_machine=vms[2], name='Interface 3', mac_address='00-00-00-00-00-03'), ) VMInterface.objects.bulk_create(interfaces) # Assign primary IPs for filtering ipaddresses = ( IPAddress(address='192.0.2.1/24', assigned_object=interfaces[0]), IPAddress(address='192.0.2.2/24', assigned_object=interfaces[1]), ) IPAddress.objects.bulk_create(ipaddresses) VirtualMachine.objects.filter(pk=vms[0].pk).update( primary_ip4=ipaddresses[0]) VirtualMachine.objects.filter(pk=vms[1].pk).update( primary_ip4=ipaddresses[1])
def setUpTestData(cls): regions = ( Region(name='Test Region 1', slug='test-region-1'), Region(name='Test Region 2', slug='test-region-2'), Region(name='Test Region 3', slug='test-region-3'), ) # Can't use bulk_create for models with MPTT fields for r in regions: r.save() sites = ( Site(name='Test Site 1', slug='test-site-1'), Site(name='Test Site 2', slug='test-site-2'), Site(name='Test Site 3', slug='test-site-3'), ) Site.objects.bulk_create(sites) device_roles = ( DeviceRole(name='Device Role 1', slug='device-role-1'), DeviceRole(name='Device Role 2', slug='device-role-2'), DeviceRole(name='Device Role 3', slug='device-role-3'), ) DeviceRole.objects.bulk_create(device_roles) platforms = ( Platform(name='Platform 1', slug='platform-1'), Platform(name='Platform 2', slug='platform-2'), Platform(name='Platform 3', slug='platform-3'), ) Platform.objects.bulk_create(platforms) cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ) ClusterGroup.objects.bulk_create(cluster_groups) cluster_type = ClusterType.objects.create(name='Cluster Type 1', slug='cluster-type-1') clusters = ( Cluster(name='Cluster 1', type=cluster_type), Cluster(name='Cluster 2', type=cluster_type), Cluster(name='Cluster 3', type=cluster_type), ) Cluster.objects.bulk_create(clusters) tenant_groups = ( TenantGroup(name='Tenant Group 1', slug='tenant-group-1'), TenantGroup(name='Tenant Group 2', slug='tenant-group-2'), TenantGroup(name='Tenant Group 3', slug='tenant-group-3'), ) for tenantgroup in tenant_groups: tenantgroup.save() tenants = ( Tenant(name='Tenant 1', slug='tenant-1'), Tenant(name='Tenant 2', slug='tenant-2'), Tenant(name='Tenant 3', slug='tenant-3'), ) Tenant.objects.bulk_create(tenants) for i in range(0, 3): is_active = bool(i % 2) c = ConfigContext.objects.create( name='Config Context {}'.format(i + 1), is_active=is_active, data='{"foo": 123}') c.regions.set([regions[i]]) c.sites.set([sites[i]]) c.roles.set([device_roles[i]]) c.platforms.set([platforms[i]]) c.cluster_groups.set([cluster_groups[i]]) c.clusters.set([clusters[i]]) c.tenant_groups.set([tenant_groups[i]]) c.tenants.set([tenants[i]])
def mutate_and_get_payload(cls, input, context, info): temp = ClusterGroup() fields = ['name', 'slug'] return NewClusterGroup(cluster_group=set_and_save(fields, input, temp))
def setUpTestData(cls): cluster_types = ( ClusterType(name='Cluster Type 1', slug='cluster-type-1'), ClusterType(name='Cluster Type 2', slug='cluster-type-2'), ClusterType(name='Cluster Type 3', slug='cluster-type-3'), ) ClusterType.objects.bulk_create(cluster_types) cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ) ClusterGroup.objects.bulk_create(cluster_groups) regions = ( Region(name='Test Region 1', slug='test-region-1'), Region(name='Test Region 2', slug='test-region-2'), Region(name='Test Region 3', slug='test-region-3'), ) # Can't use bulk_create for models with MPTT fields for r in regions: r.save() sites = ( Site(name='Test Site 1', slug='test-site-1', region=regions[0]), Site(name='Test Site 2', slug='test-site-2', region=regions[1]), Site(name='Test Site 3', slug='test-site-3', region=regions[2]), ) Site.objects.bulk_create(sites) clusters = ( Cluster(name='Cluster 1', type=cluster_types[0], group=cluster_groups[0], site=sites[0]), Cluster(name='Cluster 2', type=cluster_types[1], group=cluster_groups[1], site=sites[1]), Cluster(name='Cluster 3', type=cluster_types[2], group=cluster_groups[2], site=sites[2]), ) Cluster.objects.bulk_create(clusters) platforms = ( Platform(name='Platform 1', slug='platform-1'), Platform(name='Platform 2', slug='platform-2'), Platform(name='Platform 3', slug='platform-3'), ) Platform.objects.bulk_create(platforms) roles = ( DeviceRole(name='Device Role 1', slug='device-role-1'), DeviceRole(name='Device Role 2', slug='device-role-2'), DeviceRole(name='Device Role 3', slug='device-role-3'), ) DeviceRole.objects.bulk_create(roles) tenant_groups = ( TenantGroup(name='Tenant group 1', slug='tenant-group-1'), TenantGroup(name='Tenant group 2', slug='tenant-group-2'), TenantGroup(name='Tenant group 3', slug='tenant-group-3'), ) for tenantgroup in tenant_groups: tenantgroup.save() tenants = ( Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]), Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1]), Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]), ) Tenant.objects.bulk_create(tenants) vms = ( VirtualMachine(name='Virtual Machine 1', cluster=clusters[0], platform=platforms[0], role=roles[0], tenant=tenants[0], status=VirtualMachineStatusChoices.STATUS_ACTIVE, vcpus=1, memory=1, disk=1, local_context_data={"foo": 123}), VirtualMachine(name='Virtual Machine 2', cluster=clusters[1], platform=platforms[1], role=roles[1], tenant=tenants[1], status=VirtualMachineStatusChoices.STATUS_STAGED, vcpus=2, memory=2, disk=2), VirtualMachine(name='Virtual Machine 3', cluster=clusters[2], platform=platforms[2], role=roles[2], tenant=tenants[2], status=VirtualMachineStatusChoices.STATUS_OFFLINE, vcpus=3, memory=3, disk=3), ) VirtualMachine.objects.bulk_create(vms) interfaces = ( Interface(virtual_machine=vms[0], name='Interface 1', mac_address='00-00-00-00-00-01'), Interface(virtual_machine=vms[1], name='Interface 2', mac_address='00-00-00-00-00-02'), Interface(virtual_machine=vms[2], name='Interface 3', mac_address='00-00-00-00-00-03'), ) Interface.objects.bulk_create(interfaces)
def setUpTestData(cls): regions = ( Region(name='Test Region 1', slug='test-region-1'), Region(name='Test Region 2', slug='test-region-2'), Region(name='Test Region 3', slug='test-region-3'), ) for r in regions: r.save() site_groups = ( SiteGroup(name='Site Group 1', slug='site-group-1'), SiteGroup(name='Site Group 2', slug='site-group-2'), SiteGroup(name='Site Group 3', slug='site-group-3'), ) for site_group in site_groups: site_group.save() sites = ( Site(name='Test Site 1', slug='test-site-1'), Site(name='Test Site 2', slug='test-site-2'), Site(name='Test Site 3', slug='test-site-3'), ) Site.objects.bulk_create(sites) manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1') device_types = ( DeviceType(manufacturer=manufacturer, model='Device Type 1', slug='device-type-1'), DeviceType(manufacturer=manufacturer, model='Device Type 2', slug='device-type-3'), DeviceType(manufacturer=manufacturer, model='Device Type 3', slug='device-type-4'), ) DeviceType.objects.bulk_create(device_types) device_roles = ( DeviceRole(name='Device Role 1', slug='device-role-1'), DeviceRole(name='Device Role 2', slug='device-role-2'), DeviceRole(name='Device Role 3', slug='device-role-3'), ) DeviceRole.objects.bulk_create(device_roles) platforms = ( Platform(name='Platform 1', slug='platform-1'), Platform(name='Platform 2', slug='platform-2'), Platform(name='Platform 3', slug='platform-3'), ) Platform.objects.bulk_create(platforms) cluster_groups = ( ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'), ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'), ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'), ) ClusterGroup.objects.bulk_create(cluster_groups) cluster_type = ClusterType.objects.create(name='Cluster Type 1', slug='cluster-type-1') clusters = ( Cluster(name='Cluster 1', type=cluster_type), Cluster(name='Cluster 2', type=cluster_type), Cluster(name='Cluster 3', type=cluster_type), ) Cluster.objects.bulk_create(clusters) tenant_groups = ( TenantGroup(name='Tenant Group 1', slug='tenant-group-1'), TenantGroup(name='Tenant Group 2', slug='tenant-group-2'), TenantGroup(name='Tenant Group 3', slug='tenant-group-3'), ) for tenantgroup in tenant_groups: tenantgroup.save() tenants = ( Tenant(name='Tenant 1', slug='tenant-1'), Tenant(name='Tenant 2', slug='tenant-2'), Tenant(name='Tenant 3', slug='tenant-3'), ) Tenant.objects.bulk_create(tenants) tags = create_tags('Alpha', 'Bravo', 'Charlie') for i in range(0, 3): is_active = bool(i % 2) c = ConfigContext.objects.create( name='Config Context {}'.format(i + 1), is_active=is_active, data='{"foo": 123}') c.regions.set([regions[i]]) c.site_groups.set([site_groups[i]]) c.sites.set([sites[i]]) c.device_types.set([device_types[i]]) c.roles.set([device_roles[i]]) c.platforms.set([platforms[i]]) c.cluster_groups.set([cluster_groups[i]]) c.clusters.set([clusters[i]]) c.tenant_groups.set([tenant_groups[i]]) c.tenants.set([tenants[i]]) c.tags.set([tags[i]])