Commit 5b9c2c37 authored by Venkat's avatar Venkat
Browse files

added the rest call for updateip

parent d6cc9b77
......@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
import { delay } from 'q';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
import { DialogOverviewComponent, Records } from './dialog-overview/dialog-overview.component';
import { ConsoleReporter } from 'jasmine';
//import { ConsoleReporter } from 'jasmine';
@Component({
selector: 'app-root',
......@@ -18,9 +18,7 @@ export class AppComponent {
constructor(private sampleService: SampleService, public dialog: MatDialog){
}
title = 'IPAM';
users: UserInformation[];
userInformation: UserInformation[];
title = 'IPAM';
dataSource: any;
returned_record_id: any;
returned_host_id: any;
......@@ -50,8 +48,9 @@ export class AppComponent {
ngOnInit(){
// this.getUserInformation();
//this.getAvailableIPs();
this.testRecords.push(this.new_record);
this.getAllIps();
//this.testRecords.push(this.new_record);
this.UpdateIp();
//this.getAllIps();
//this.PutRecords();
//this.getIPsByRange()
//this.PostPreambles()
......@@ -66,14 +65,7 @@ export class AppComponent {
}
displayedColumns: string[] = ['subnet_name', 'ipv4', 'ipv6', 'host', 'mac_addr', 'adapter'];
displayUserInformation(item: UserInformation[]){
item.forEach(item =>
console.log(item)
);
console.log(this.userInformation);
}
getClick(selectedValue): any{
this.selectedCell = selectedValue;
......@@ -85,19 +77,7 @@ export class AppComponent {
this.openDialog();
}
}
getUserInformation(): void {
this.sampleService.getInfo()
.toPromise()
.then((res) => {
this.userInformation = res;
this.dataSource = this.userInformation;
this.userInformation.forEach(x =>
console.log(x))
});
}
getAvailableIPs(): void{
this.sampleService.ListAvailableIPs()
......@@ -139,18 +119,18 @@ export class AppComponent {
// //return this.returned_host_id
// }
PostAdapters(hostID): any {
this.sampleService.PostAdapters(hostID)
PostAdapters(hostID, adapter_name): any {
this.sampleService.PostAdapters(hostID, adapter_name)
.toPromise()
.then((res) => {
console.log('Adapter inserted.')
})
}
DeleteHost(): void{
this.sampleService.DeleteHost(23)
DeleteHost(hostID): void{
this.sampleService.DeleteHost(hostID)
.toPromise()
.then((res) => {
console.log('success')
console.log('host deleted')
})
}
......@@ -162,7 +142,15 @@ export class AppComponent {
})
}
PostRecords(host_name): void {
UpdateIp(): void{
this.sampleService.PutIP(70, 2, 2, '192.168.0.2', '')
.toPromise()
.then((res) => {
console.log('update ip called')
});
}
PostRecords(host_name, ipv4?, ipv6?, mac_address?, adapter_name?): void {
this.sampleService.PostHosts(host_name)
.toPromise()
.then((res) => {
......@@ -170,10 +158,10 @@ export class AppComponent {
this.sampleService.AddRecord(this.returned_record_id)
.toPromise()
.then((item) => {
this.sampleService.PostAdapters(this.returned_record_id)
this.sampleService.PostAdapters(this.returned_record_id, adapter_name)
.toPromise()
.then((item) => {
this.sampleService.PostMacs(item.id)
this.sampleService.PostMacs(item.id, mac_address)
.toPromise()
.then((item) => {
let ip_id = this.ipResultSet.find(x => x.ipv4 === this.postUIObject.ipv4 || x.ipv4 === this.postUIObject.ipv6).ip_id
......@@ -204,9 +192,7 @@ export class AppComponent {
this.postUIObject.mac_address = result.mac;
this.postUIObject.adapter_name = result.adapter;
//this.postUIObject.ip_id = ip_object.id
this.PostRecords(this.postUIObject.host_name)
this.PostRecords(this.postUIObject.host_name, this.postUIObject.ipv4, this.postUIObject.ipv6, this.postUIObject.mac_address, this.postUIObject.adapter_name);
});
......@@ -214,26 +200,12 @@ export class AppComponent {
}
export interface UserInformation{
userId: Number,
ID: Number,
title: string,
completed: boolean
}
export interface PeriodicElement {
name: string;
position: Number;
weight: Number;
symbol: string;
}
export interface IPs{
id: any,
ipv4: any,
ipv6: any,
subnet: any,
mac_addr: number
mac_addr: any
}
export interface Subnets{
......@@ -272,8 +244,6 @@ export interface Hosts{
host_name: any,
}
export interface Record_Types{
Type: string
}
......
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { UserInformation, Preambles, Hosts, Adapters, MacAddresses, IPs, Subnets } from './app.component';
import { Preambles, Hosts, Adapters, MacAddresses, IPs, Subnets } from './app.component';
import { Records } from '../app/dialog-overview/dialog-overview.component';
@Injectable({
......@@ -141,27 +141,28 @@ export class SampleService {
return this.http.post<Hosts>(this.HostLocation + this.endpoint, this.host);
}
PostAdapters(hostID): Observable<Adapters> {
PostAdapters(hostID, adapter_name): Observable<Adapters> {
this.endpoint = 'ipam/createadapter/';
this.new_adapter.host = hostID;
this.new_adapter.adapter_name = 'eth0';
this.new_adapter.adapter_name = adapter_name;
return this.http.post<Adapters>(this.HostLocation + this.endpoint, this.new_adapter)
}
PostMacs(adapterID): Observable<MacAddresses>{
PostMacs(adapterID, mac_address): Observable<MacAddresses>{
this.endpoint = "ipam/createmac/";
this.new_mac.mac = '00:12:12:2a';
this.new_mac.mac = mac_address;
this.new_mac.adapter = adapterID;
return this.http.post<MacAddresses>(this.HostLocation + this.endpoint, this.new_mac);
}
PutIP(macAddress, subnet, IP_ID, IPV4, IPV6): Observable<IPs> {
PutIP(mac_id, subnet_id, IP_ID, IPV4, IPV6): Observable<IPs> {
this.endpoint = 'ipam/updateip/' + IP_ID + '/';
this.new_ip.mac_addr = macAddress;
this.new_ip.subnet = 1;
//this.new_ip.id = id;
this.new_ip.mac_addr = mac_id;
this.new_ip.subnet = subnet_id;
this.new_ip.ipv4 = IPV4;
this.new_ip.ipv6 = IPV6
return this.http.put<IPs>(this.HostLocation + this.endpoint, this.new_ip);
return this.http.patch<IPs>(this.HostLocation + this.endpoint, this.new_ip);
}
DeleteHost(id): any {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment