-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:[CUS-161] Delete Unused VM disk.
- Loading branch information
1 parent
7657fd8
commit 76ab7b5
Showing
10 changed files
with
197 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...very/src/main/java/com/tmobile/pacbot/gcp/inventory/collector/DiskInventoryCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.tmobile.pacbot.gcp.inventory.collector; | ||
|
||
|
||
import com.google.cloud.compute.v1.Disk; | ||
import com.google.cloud.compute.v1.DisksClient; | ||
import com.google.cloud.compute.v1.ListDisksRequest; | ||
import com.tmobile.pacbot.gcp.inventory.auth.GCPCredentialsProvider; | ||
import com.tmobile.pacbot.gcp.inventory.vo.DiskVH; | ||
import com.tmobile.pacbot.gcp.inventory.vo.ProjectVH; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import com.google.cloud.compute.v1.DisksClient.ListPagedResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DiskInventoryCollector { | ||
@Autowired | ||
GCPCredentialsProvider gcpCredentialsProvider; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DiskInventoryCollector.class); | ||
|
||
public List<DiskVH> fetchDiskInventory(ProjectVH project) throws IOException { | ||
List<DiskVH> diskList = new ArrayList<>(); | ||
logger.debug("Project id:{}",project.getProjectNumber()); | ||
|
||
DisksClient disksClient=gcpCredentialsProvider.getDiskClient(project.getProjectId()); | ||
ListDisksRequest request = ListDisksRequest.newBuilder() | ||
.setProject(project.getProjectId()) | ||
.build(); | ||
ListPagedResponse diskResponse = disksClient.list(request); | ||
logger.info("Disk entry {}", diskResponse); | ||
for (Disk disk : diskResponse.iterateAll()) { | ||
logger.info("Disk iterator {}", disk); | ||
|
||
DiskVH diskVH=new DiskVH(); | ||
diskVH.setName(disk.getName()); | ||
diskVH.setKind(disk.getKind()); | ||
diskVH.setSizeGb(disk.getSizeGb()); | ||
diskVH.setZone(disk.getZone()); | ||
diskVH.setStatus(disk.getStatus()); | ||
diskVH.setType(disk.getType()); | ||
diskVH.setId(String.valueOf(disk.getId())); | ||
diskVH.setProjectName(project.getProjectName()); | ||
diskVH.setProjectId(project.getProjectId()); | ||
diskVH.setLicenses(disk.getLicensesList()); | ||
diskVH.setUsers(disk.getUsersList()); | ||
diskVH.setLicenseCodes(disk.getLicenseCodesList()); | ||
diskList.add(diskVH); | ||
|
||
logger.info("Disk exit {}", diskVH); | ||
} | ||
|
||
logger.info("Disk list {}", diskList); | ||
|
||
return diskList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
jobs/gcp-discovery/src/main/java/com/tmobile/pacbot/gcp/inventory/vo/DiskVH.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.tmobile.pacbot.gcp.inventory.vo; | ||
|
||
import com.google.protobuf.ProtocolStringList; | ||
|
||
import java.util.List; | ||
|
||
public class DiskVH extends GCPVH{ | ||
|
||
private String name; | ||
private String kind; | ||
private long sizeGb; | ||
private String zone; | ||
private String status; | ||
private String type; | ||
private ProtocolStringList licenses; | ||
private ProtocolStringList users; | ||
private List<Long>licenseCodes; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getKind() { | ||
return kind; | ||
} | ||
|
||
public void setKind(String kind) { | ||
this.kind = kind; | ||
} | ||
|
||
public long getSizeGb() { | ||
return sizeGb; | ||
} | ||
|
||
public void setSizeGb(long sizeGb) { | ||
this.sizeGb = sizeGb; | ||
} | ||
|
||
public String getZone() { | ||
return zone; | ||
} | ||
|
||
public void setZone(String zone) { | ||
this.zone = zone; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(String status) { | ||
this.status = status; | ||
} | ||
|
||
public ProtocolStringList getLicenses() { | ||
return licenses; | ||
} | ||
|
||
public void setLicenses(ProtocolStringList licenses) { | ||
this.licenses = licenses; | ||
} | ||
|
||
public ProtocolStringList getUsers() { | ||
return users; | ||
} | ||
|
||
public void setUsers(ProtocolStringList users) { | ||
this.users = users; | ||
} | ||
|
||
public List<Long> getLicenseCodes() { | ||
return licenseCodes; | ||
} | ||
|
||
public void setLicenseCodes(List<Long> licenseCodes) { | ||
this.licenseCodes = licenseCodes; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.