Skip to content

Commit

Permalink
feat(app,back) add netbox v4 option
Browse files Browse the repository at this point in the history
  • Loading branch information
helderbetiol committed Sep 25, 2024
1 parent fb010bc commit 2df9ab4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
15 changes: 14 additions & 1 deletion APP/lib/models/netbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ class Nbox {
String userName;
String userPassword;
String port;
String? version;

Nbox(this.userName, this.userPassword, this.port);

Map<String, dynamic> toMap() {
if (version != null) {
return <String, dynamic>{
'username': userName,
'password': userPassword,
'port': port,
'version': version,
};
}
return <String, dynamic>{
'username': userName,
'password': userPassword,
Expand All @@ -19,11 +28,15 @@ class Nbox {
}

factory Nbox.fromMap(Map<String, dynamic> map) {
return Nbox(
final nbox = Nbox(
map['username'].toString(),
map['password'].toString(),
map['port'].toString(),
);
if (map['version'] != null) {
nbox.version = map['version'].toString();
}
return nbox;
}

String toJson() => json.encode(toMap());
Expand Down
42 changes: 40 additions & 2 deletions APP/lib/widgets/tools/create_netbox_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class _CreateNboxPopupState extends State<CreateNboxPopup> {
String? _port;
bool _isLoading = false;
bool _isSmallDisplay = false;
String netboxVersion = "v4.1-3.0.2";

@override
void initState() {
Expand All @@ -45,7 +46,7 @@ class _CreateNboxPopupState extends State<CreateNboxPopup> {
return Center(
child: Container(
width: 500,
constraints: const BoxConstraints(maxHeight: 300),
constraints: const BoxConstraints(maxHeight: 360),
margin: const EdgeInsets.symmetric(horizontal: 20),
decoration: PopupDecoration,
child: Padding(
Expand All @@ -71,6 +72,41 @@ class _CreateNboxPopupState extends State<CreateNboxPopup> {
),
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.only(bottom: 10, right: 10),
child: DropdownButtonFormField<String>(
isExpanded: true,
borderRadius: BorderRadius.circular(12.0),
decoration: GetFormInputDecoration(
false,
"Version",
icon: Icons.bookmark,
),
value: netboxVersion,
items: const [
DropdownMenuItem<String>(
value: "v4.1-3.0.2",
child: Text(
"v4.1-3.0.2",
overflow: TextOverflow.ellipsis,
),
),
DropdownMenuItem<String>(
value: "v3.7-2.8.0",
child: Text(
"v3.7-2.8.0",
overflow: TextOverflow.ellipsis,
),
),
],
onChanged: (String? value) {
// clean the whole form
setState(() {
netboxVersion = value!;
});
},
),
),
CustomFormField(
save: (newValue) => _userName = newValue,
label: localeMsg.toolUsername(toolName),
Expand Down Expand Up @@ -147,7 +183,9 @@ class _CreateNboxPopupState extends State<CreateNboxPopup> {
final messenger = ScaffoldMessenger.of(context);
Result<void, Exception> result;
if (widget.tool == Tools.netbox) {
result = await createNetbox(Nbox(_userName!, _userPassword!, _port!));
final netbox = Nbox(_userName!, _userPassword!, _port!);
netbox.version = netboxVersion;
result = await createNetbox(netbox);
} else {
//nautobot
result = await createNautobot(Nbox(_userName!, _userPassword!, _port!));
Expand Down
5 changes: 4 additions & 1 deletion BACK/app/handlers/docker/netbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ func CreateNetbox(c *gin.Context) {
if newNetbox.Port == "" {
newNetbox.Port = "8000"
}
if newNetbox.Version == "" {
newNetbox.Port = "v4.1-3.0.2"
}

if _, err := os.Stat(netboxDir); os.IsNotExist(err) {
// Clone github repo
println("Cloning Netbox git repo...")
args := []string{"clone", "-b", "release", "https://github.com/netbox-community/netbox-docker.git"}
args := []string{"clone", "-b", "3.0.2", "https://github.com/netbox-community/netbox-docker.git"}
cmd := exec.Command("git", args...)
var stderr bytes.Buffer
cmd.Stderr = &stderr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
version: '3.4'
services:
netbox:
image: docker.io/netboxcommunity/netbox:${VERSION-{{.Version}}}
ports:
- "{{.Port}}:8080"
environment:
- SKIP_SUPERUSER=false
- SUPERUSER_NAME={{.Username}}
- SUPERUSER_PASSWORD={{.Password}}
netbox-worker:
image: docker.io/netboxcommunity/netbox:${VERSION-{{.Version}}}
netbox-housekeeping:
image: docker.io/netboxcommunity/netbox:${VERSION-{{.Version}}}
1 change: 1 addition & 0 deletions BACK/app/models/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
type Netbox struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Version string `json:"version"`
Port string `json:"port"`
}

Expand Down

0 comments on commit 2df9ab4

Please sign in to comment.