@@ -2589,6 +2589,25 @@ func (s *SBaremetalServer) GetMetadata() (*jsonutils.JSONDict, error) {
25892589}
25902590
25912591func (s * SBaremetalServer ) GetRootDiskMatcher () (* api.BaremetalRootDiskMatcher , error ) {
2592+ matcher , err := s .getRootDiskMatcher ()
2593+ if err != nil && errors .Cause (err ) != errors .ErrNotFound {
2594+ return nil , errors .Wrap (err , "getRootDiskMatcher" )
2595+ }
2596+ if matcher == nil {
2597+ matcher = & api.BaremetalRootDiskMatcher {}
2598+ }
2599+ rootDiskObj , err := s .GetRootDiskObj ()
2600+ if err != nil {
2601+ return nil , errors .Wrap (err , "GetRootDiskObj" )
2602+ }
2603+ pciPath , _ := rootDiskObj .GetString ("pci_path" )
2604+ if pciPath != "" {
2605+ matcher .PCIPath = pciPath
2606+ }
2607+ return matcher , nil
2608+ }
2609+
2610+ func (s * SBaremetalServer ) getRootDiskMatcher () (* api.BaremetalRootDiskMatcher , error ) {
25922611 metadata , err := s .GetMetadata ()
25932612 if err != nil {
25942613 return nil , errors .Wrap (err , "get metadata" )
@@ -2626,6 +2645,14 @@ func (s *SBaremetalServer) GetDiskConfig() ([]*api.BaremetalDiskConfig, error) {
26262645 return baremetal .GetLayoutRaidConfig (layouts ), nil
26272646}
26282647
2648+ func (s * SBaremetalServer ) GetRootDiskObj () (* jsonutils.JSONDict , error ) {
2649+ disks , _ := s .desc .GetArray ("disks" )
2650+ if len (disks ) == 0 {
2651+ return nil , errors .Error ("Empty disks in desc" )
2652+ }
2653+ return disks [0 ].(* jsonutils.JSONDict ), nil
2654+ }
2655+
26292656func (s * SBaremetalServer ) NewConfigedSSHPartitionTool (term * ssh.Client ) (* disktool.SSHPartitionTool , error ) {
26302657 raid , nonRaid , pcie , err := detect_storages .DetectStorageInfo (term , false )
26312658 if err != nil {
@@ -2688,9 +2715,8 @@ func (s *SBaremetalServer) DoDiskConfig(term *ssh.Client) (*disktool.SSHPartitio
26882715 if err != nil {
26892716 return nil , fmt .Errorf ("CalculateLayout: %v" , err )
26902717 }
2691- log .Errorf ("===layouts: %s" , jsonutils .Marshal (layouts ).PrettyString ())
26922718 diskConfs := baremetal .GroupLayoutResultsByDriverAdapter (layouts )
2693- log .Errorf ("=== diskConfs: %s" , jsonutils .Marshal (diskConfs ).PrettyString ())
2719+ log .Errorf ("%s layouts: %s, diskConfs: %s" , s . GetName (), jsonutils . Marshal ( layouts ). PrettyString () , jsonutils .Marshal (diskConfs ).PrettyString ())
26942720 for _ , dConf := range diskConfs {
26952721 driver := dConf .Driver
26962722 raidDrv := raiddrivers .GetDriver (driver , term )
@@ -2728,7 +2754,7 @@ func (s *SBaremetalServer) DoDiskConfig(term *ssh.Client) (*disktool.SSHPartitio
27282754 maxTries := 60
27292755 for tried := 0 ; ! tool .IsAllDisksReady () && tried < maxTries ; tried ++ {
27302756 time .Sleep (5 * time .Second )
2731- tool .RetrieveDiskInfo ()
2757+ tool .RetrieveDiskInfo (matcher )
27322758 log .Warningf ("disktool not ready string: %s" , tool .DebugString ())
27332759 }
27342760
@@ -2782,10 +2808,10 @@ func (s *SBaremetalServer) doCreateRoot(term *ssh.Client, devName string, disabl
27822808 return nil
27832809}
27842810
2785- func (s * SBaremetalServer ) DoPartitionDisk (tool * disktool.SSHPartitionTool , term * ssh.Client , disableImageCache bool ) ([]* disktool.Partition , error ) {
2811+ func (s * SBaremetalServer ) DoPartitionDisk (tool * disktool.SSHPartitionTool , term * ssh.Client , disableImageCache bool ) (* disktool. DiskPartitions , []* disktool.Partition , error ) {
27862812 raid , nonRaid , pcie , err := detect_storages .DetectStorageInfo (term , false )
27872813 if err != nil {
2788- return nil , err
2814+ return nil , nil , errors . Wrap ( err , "DetectStorageInfo" )
27892815 }
27902816 storages := make ([]* baremetal.BaremetalStorage , 0 )
27912817 storages = append (storages , raid ... )
@@ -2807,33 +2833,34 @@ func (s *SBaremetalServer) DoPartitionDisk(tool *disktool.SSHPartitionTool, term
28072833
28082834 disks , _ := s .desc .GetArray ("disks" )
28092835 if len (disks ) == 0 {
2810- return nil , errors .Error ("Empty disks in desc" )
2836+ return nil , nil , errors .Error ("Empty disks in desc" )
28112837 }
28122838
28132839 rootImageId := s .GetRootTemplateId ()
28142840 diskOffset := 0
2841+ rootDisk := tool .GetRootDisk ()
28152842 if len (rootImageId ) > 0 {
2816- rootDisk := disks [0 ]
2817- rootSize , _ := rootDisk .Int ("size" )
2818- err = s .doCreateRoot (term , tool . GetRootDisk () .GetDevName (), disableImageCache )
2843+ rootDiskObj := disks [0 ]
2844+ rootSize , _ := rootDiskObj .Int ("size" )
2845+ err = s .doCreateRoot (term , rootDisk .GetDevName (), disableImageCache )
28192846 if err != nil {
2820- return nil , errors .Wrap (err , "Failed to create root" )
2847+ return rootDisk , nil , errors .Wrap (err , "Failed to create root" )
28212848 }
28222849 tool .RetrievePartitionInfo ()
28232850 parts := tool .GetPartitions ()
28242851 if len (parts ) == 0 {
2825- return nil , errors .Error ("Root disk create failed, no partitions" )
2852+ return rootDisk , nil , errors .Error ("Root disk create failed, no partitions" )
28262853 }
28272854 log .Infof ("Resize root to %d MB" , rootSize )
28282855 if err := tool .ResizePartition (0 , rootSize ); err != nil {
2829- return nil , errors .Wrapf (err , "Fail to resize root to %d" , rootSize )
2856+ return rootDisk , nil , errors .Wrapf (err , "Fail to resize root to %d" , rootSize )
28302857 }
28312858 diskOffset = 1
28322859 } else {
28332860 tool .RetrievePartitionInfo ()
28342861 parts := tool .GetPartitions ()
28352862 if len (parts ) > 0 {
2836- return nil , errors .Error ("should no partition!!!" )
2863+ return rootDisk , nil , errors .Error ("should no partition!!!" )
28372864 }
28382865 }
28392866
@@ -2848,16 +2875,16 @@ func (s *SBaremetalServer) DoPartitionDisk(tool *disktool.SSHPartitionTool, term
28482875 driver , _ := disk .GetString ("driver" )
28492876 log .Infof ("Create partition %d %s" , sz , fs )
28502877 if err := tool .CreatePartition (- 1 , sz , fs , true , driver , uuid ); err != nil {
2851- return nil , errors .Wrapf (err , "Fail to create disk %s" , disk .String ())
2878+ return rootDisk , nil , errors .Wrapf (err , "Fail to create disk %s" , disk .String ())
28522879 }
28532880 }
28542881 }
28552882 log .Infof ("Finish create partitions" )
28562883
2857- return tool .GetPartitions (), nil
2884+ return rootDisk , tool .GetPartitions (), nil
28582885}
28592886
2860- func (s * SBaremetalServer ) DoRebuildRootDisk (tool * disktool.SSHPartitionTool , term * ssh.Client , disableImageCache bool ) ([]* disktool.Partition , error ) {
2887+ func (s * SBaremetalServer ) DoRebuildRootDisk (tool * disktool.SSHPartitionTool , term * ssh.Client , disableImageCache bool ) (* disktool. DiskPartitions , []* disktool.Partition , error ) {
28612888 // raid, nonRaid, pcie, err := detect_storages.DetectStorageInfo(term, false)
28622889 // if err != nil {
28632890 // return nil, err
@@ -2882,24 +2909,24 @@ func (s *SBaremetalServer) DoRebuildRootDisk(tool *disktool.SSHPartitionTool, te
28822909
28832910 disks , _ := s .desc .GetArray ("disks" )
28842911 if len (disks ) == 0 {
2885- return nil , fmt .Errorf ("Empty disks in desc" )
2912+ return nil , nil , fmt .Errorf ("Empty disks in desc" )
28862913 }
28872914
28882915 rootDisk := disks [0 ]
28892916 rootSize , _ := rootDisk .Int ("size" )
28902917 rd := tool .GetRootDisk ()
28912918 err := s .doCreateRoot (term , rd .GetDevName (), disableImageCache )
28922919 if err != nil {
2893- return nil , fmt .Errorf ("Failed to create root: %v" , err )
2920+ return rd , nil , fmt .Errorf ("Failed to create root: %v" , err )
28942921 }
28952922 tool .RetrievePartitionInfo ()
28962923 if err := rd .ReInitInfo (); err != nil {
2897- return nil , errors .Wrap (err , "Reinit root disk after create root" )
2924+ return rd , nil , errors .Wrap (err , "Reinit root disk after create root" )
28982925 }
28992926
29002927 log .Infof ("Resize root to %d MB" , rootSize )
29012928 if err := rd .ResizePartition (rootSize ); err != nil {
2902- return nil , fmt .Errorf ("Fail to resize root to %d, err: %v" , rootSize , err )
2929+ return rd , nil , fmt .Errorf ("Fail to resize root to %d, err: %v" , rootSize , err )
29032930 }
29042931 if len (disks ) > 1 {
29052932 for _ , disk := range disks [1 :] {
@@ -2926,10 +2953,10 @@ func (s *SBaremetalServer) DoRebuildRootDisk(tool *disktool.SSHPartitionTool, te
29262953 for _ , d := range restDisks {
29272954 parts = append (parts , d .GetPartitions ()... )
29282955 }
2929- return parts , nil
2956+ return rd , parts , nil
29302957}
29312958
2932- func (s * SBaremetalServer ) SyncPartitionSize (term * ssh.Client , parts []* disktool.Partition ) ([]jsonutils.JSONObject , error ) {
2959+ func (s * SBaremetalServer ) SyncPartitionSize (term * ssh.Client , rootDisk * disktool. DiskPartitions , parts []* disktool.Partition ) ([]jsonutils.JSONObject , error ) {
29332960 disks , _ := s .desc .GetArray ("disks" )
29342961
29352962 // calculate root partitions count
@@ -2941,18 +2968,24 @@ func (s *SBaremetalServer) SyncPartitionSize(term *ssh.Client, parts []*disktool
29412968 rootParts := parts [0 :rootPartsCnt ]
29422969 dataParts := parts [rootPartsCnt :]
29432970 idx := 0
2971+
2972+ // set root disk attributes that returns to region service
29442973 size := (rootParts [len (rootParts )- 1 ].GetEnd () + 1 ) * 512 / 1024 / 1024
2945- disks [idx ].(* jsonutils.JSONDict ).Set ("size" , jsonutils .NewInt (int64 (size )))
2974+ rootDiskObj := disks [idx ].(* jsonutils.JSONDict )
2975+ rootDiskObj .Set ("size" , jsonutils .NewInt (int64 (size )))
2976+ rootDiskObj .Set ("pci_path" , jsonutils .NewString (rootDisk .GetPCIPath ()))
2977+
29462978 idx += 1
29472979 for _ , p := range dataParts {
29482980 sizeMB , err := p .GetSizeMB ()
29492981 if err != nil {
2950- return nil , err
2982+ return nil , errors . Wrap ( err , "GetSizeMB" )
29512983 }
29522984 disks [idx ].(* jsonutils.JSONDict ).Set ("size" , jsonutils .NewInt (int64 (sizeMB )))
29532985 disks [idx ].(* jsonutils.JSONDict ).Set ("dev" , jsonutils .NewString (p .GetDev ()))
29542986 idx ++
29552987 }
2988+ s .desc .Set ("disks" , jsonutils .NewArray (disks ... ))
29562989 return disks , nil
29572990}
29582991
0 commit comments