소스 검색

Extend example custom script to generate output

Jeremy Stretch 6 년 전
부모
커밋
463c636301
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      docs/additional-features/custom-scripts.md

+ 14 - 0
docs/additional-features/custom-scripts.md

@@ -165,4 +165,18 @@ class NewBranchScript(Script):
             )
             switch.save()
             self.log_success("Created new switch: {}".format(switch))
+
+        # Generate a CSV table of new devices
+        output = [
+            'name,make,model'
+        ]
+        for switch in Device.objects.filter(site=site):
+            attrs = [
+                switch.name,
+                switch.device_type.manufacturer.name,
+                switch.device_type.model
+            ]
+            output.append(','.join(attrs))
+
+        return '\n'.join(output)
 ```