I work as a storage technician, and I'm looking for ways to automate some of the tasks. SQL development is not in my job description, be gentle.
I have tried to model a database following the procedures and layout of a storage array.
One storage Array is identied with it's serial number. There are no two arrays with the same serial.
An array can have several Ports. A port has a name, and one array cannot have two ports with the same name.
A port can have several HostGroups. A hostgroup has a name, and one port cannot have two hostgroups with the same name. However, another port can (and will) have a hostgroup with the same name.
An array has several PhysicalHosts. A PhysicalHost has a name, and this name is unique. An array cannot have two PhysicalHosts with the same name.
Contrary to what you may think, a HostGroup is not a group of hosts. It's more the representation of a PhysicalHost on a particular port. Typically, a HostGroup is created on two ports for redundancy, ie there are two HostGroups with the same name on a pair of ports.
Therefore, standard operating procedure dictates that the name of the HostGroup is the same as the PhysicalHost. All HostGroups with the same name belong to the same PhysicalHost.
All tables have an ID column with the uniqueidentifier datatype. This is set as rowid with newid() as default.
I have modeled the relations using the ID column.
I also have a RawData table, containing the current configuration from the storage array. This data is populated by using bulk import from a csv file the management application outputs. I decided to not preprocess this file, I just import it as is and use select statements to get what I want.
The RawData table will have many redundancies, what I have described above is only a subset of the actual information I'm trying to process and there are reasons for the apparent redundancies.
By using the following select statement I can get the existing Array-Port-HostGroup combinations:
SELECT DISTINCT SerialNumber
,PortDisplayName
,Hostgroupname
FROM RawData
WHERE SerialNumber IS NOT NULL AND
PortDisplayName IS NOT NULL AND
Hostgroupname IS NOT NULL
Using similar statements and just using manual inserts, I have populated the Array, Port and PhysicalHost tables.
In practice, I may at most have 3 or 4 arrays to manage. Each array has maybe 24 ports. This information is virtually static as well.
However, I would like to automate the HostGroup inserts.
This statement does what I want:
INSERT INTO HostGroup
(rPhysicalHost
,rPort
,Name)
SELECT
(SELECT PhysicalHost.PhysicalHostID
FROM PhysicalHost
WHERE PhysicalHost.Name = 'MyHostNameA'),
(SELECT Port.PortID
FROM Port
WHERE Port.Name = 'MyPort0' AND Port.rArray =
(SELECT Array.ArrayID
FROM Array
WHERE Array.serial = '123456789')
)
,'MyHostNameA'
In this example, MyHostNameA is both the physical host name being referenced, and the name of the hostgroup I am inserting. This may not always be the case, depending on the operating procedures.
Now, to the actual question:
How can I take the output from the select statements where I get the Array-Port-HostGroup combination, and pass this to Insert statement to populate the HostGroups table?
I have tried to model a database following the procedures and layout of a storage array.
One storage Array is identied with it's serial number. There are no two arrays with the same serial.
An array can have several Ports. A port has a name, and one array cannot have two ports with the same name.
A port can have several HostGroups. A hostgroup has a name, and one port cannot have two hostgroups with the same name. However, another port can (and will) have a hostgroup with the same name.
An array has several PhysicalHosts. A PhysicalHost has a name, and this name is unique. An array cannot have two PhysicalHosts with the same name.
Contrary to what you may think, a HostGroup is not a group of hosts. It's more the representation of a PhysicalHost on a particular port. Typically, a HostGroup is created on two ports for redundancy, ie there are two HostGroups with the same name on a pair of ports.
Therefore, standard operating procedure dictates that the name of the HostGroup is the same as the PhysicalHost. All HostGroups with the same name belong to the same PhysicalHost.
All tables have an ID column with the uniqueidentifier datatype. This is set as rowid with newid() as default.
I have modeled the relations using the ID column.
I also have a RawData table, containing the current configuration from the storage array. This data is populated by using bulk import from a csv file the management application outputs. I decided to not preprocess this file, I just import it as is and use select statements to get what I want.
The RawData table will have many redundancies, what I have described above is only a subset of the actual information I'm trying to process and there are reasons for the apparent redundancies.
By using the following select statement I can get the existing Array-Port-HostGroup combinations:
SELECT DISTINCT SerialNumber
,PortDisplayName
,Hostgroupname
FROM RawData
WHERE SerialNumber IS NOT NULL AND
PortDisplayName IS NOT NULL AND
Hostgroupname IS NOT NULL
Using similar statements and just using manual inserts, I have populated the Array, Port and PhysicalHost tables.
In practice, I may at most have 3 or 4 arrays to manage. Each array has maybe 24 ports. This information is virtually static as well.
However, I would like to automate the HostGroup inserts.
This statement does what I want:
INSERT INTO HostGroup
(rPhysicalHost
,rPort
,Name)
SELECT
(SELECT PhysicalHost.PhysicalHostID
FROM PhysicalHost
WHERE PhysicalHost.Name = 'MyHostNameA'),
(SELECT Port.PortID
FROM Port
WHERE Port.Name = 'MyPort0' AND Port.rArray =
(SELECT Array.ArrayID
FROM Array
WHERE Array.serial = '123456789')
)
,'MyHostNameA'
In this example, MyHostNameA is both the physical host name being referenced, and the name of the hostgroup I am inserting. This may not always be the case, depending on the operating procedures.
Now, to the actual question:
How can I take the output from the select statements where I get the Array-Port-HostGroup combination, and pass this to Insert statement to populate the HostGroups table?