Uzamčený move deployed machines to other tfs project

  • 15. února 2012 13:12
     
     

    Hi

    is there a simple way to move a deployed environment from one team project to another?

    I've tried to change the description field in SCVMM on the machine but TFS just rollback my changes. So where does it keep the information?

    I know I can store each machine in the library and then redeploy them in a new team project, but thats hard way to do with many machines.

    Regards Kim

Všechny reakce

  • 20. února 2012 9:24
    Moderátor
     
     

    Hello Kim,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thanks.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us

  • 22. února 2012 22:22
    Vlastník
     
     Navržená odpověď
    Environments are not shared across projects. Changing the description will not help, as you have found out. You can store the individual Lab systems from your environment into your SCVMM library and then create an environment out of those stored virtual machines from Project 2.

    Trevor Hancock (Microsoft)
    Please remember to "Mark As Answer" the replies that help.

  • 17. dubna 2012 5:41
     
     

    Hi

    Did you find a solution where we don't have to get around the library?

    thanks

    Kim

  • 29. července 2012 20:24
     
     

    Kim,

    If you are trying to move a Lab Management/MTM environment between team projects, it is possible, but it involves directly editing the data in the TFS database, however, I do not recommend doing it. I don't remember the schema off the top of my head, but I can look into it tomorrow if you still need this question answered.

    Jarrett

  • 30. července 2012 4:42
     
     

    Hi Jarrett,

    Yes, we would still very much like this information, as we have different teams (each having own TFS project) and we often are in a situation where an configured environment (including snapshots) can be used in another team.

    Best regards, Rasmus (colleague to Kim)

  • 30. července 2012 15:19
     
      Obsahuje kód
    Rasmus,

    When updating the database, you change the Team Project the environment is associated with, so it shows up under the newly-associated team project, not both. Just wanted to clarify that point.

    Once again, I have done this before on a few occasions, but I do not recommend doing this unless you absolutely need to. I take no responsibility for your TFS system by running these queries. I'm only describing this for education purposes.

    You'll need to gather the following information: Team Project Collection name, Team Project name, Environment name, and names of the machines in the environment. For the purposes of this discussion, we will assume the following names:

        Team Project Collection name - MyCollection
        Team Project name - AlphaProject
        Environment name - Alpha Customer Demo
        Machine names - AC-Web, AC-Services, AC-DB

    You'll need to perform all of the following actions on your TFS Collection DB. This database should be called something like "Tfs_[Team Project Collection name]". Using the name listed above, the TFS Collection DB would be called "Tfs_MyCollection". Once you've connected to that DB, you'll need to locate the following tables:

        LabObject - The main linking table that connects various tables with more specific data. This table also contains the names of the Lab Environment and the Lab Machines.
        LabProject - The table that links the ProjectId to Team Project name.

    Find the Team Project you would like the environment to be a part of in the LabProject table. You can do this by running the following query:

    SELECT [ProjectId], [ProjectName] FROM [Tfs_%CollectionName%].[dbo].[LabProject] where ProjectName = '%TeamProjectName%'

    With our names above:

    SELECT [ProjectId], [ProjectName] FROM [Tfs_MyCollection].[dbo].[LabProject] where ProjectName = 'AlphaProject'
      -- Returns D77640D4-1238-450F-A9E6-787130B12CB7 as the ProjectId, for example

    This will give you the ProjectId. Copy this information down some where because you'll need it in another query. Now, we are going to find the Lab Environment. We can do this by running the following query:

    SELECT [LabObjectId], [Name], [Description],[ObjectType], [ParentId], [ContainerId], [PendingOperationId], [FailedOperationId], [InUseCount], [UsedId], [LabGuid], [CreationTime], [CreatedBy], [LastModifiedTime], [ModifiedBy], [LastAccessedTime]
      FROM [Tfs_%CollectionName%].[dbo].[LabObject]
      WHERE ObjectType = 'LabEnvironment'
      AND Name = '%EnvironmentName%'
     
    With our names above:

    SELECT [LabObjectId], [Name], [Description],[ObjectType], [ParentId], [ContainerId], [PendingOperationId], [FailedOperationId], [InUseCount], [UsedId], [LabGuid], [CreationTime], [CreatedBy], [LastModifiedTime], [ModifiedBy], [LastAccessedTime]
      FROM [Tfs_MyCollection].[dbo].[LabObject]
      WHERE ObjectType = 'LabEnvironment'
      AND Name = 'Alpha Customer Demo'
      -- Returns 61 as the LabObjectId, for example
     
    Copy down the LabObjectId. This gives us the Id for the Lab Environment. Now, we need to find the IDs of the machines that are part of the environment. This query is going to be very similar to the one above, with two things changed:

    SELECT [LabObjectId], [Name], [Description],[ObjectType], [ParentId], [ContainerId], [PendingOperationId], [FailedOperationId], [InUseCount], [UsedId], [LabGuid], [CreationTime], [CreatedBy], [LastModifiedTime], [ModifiedBy], [LastAccessedTime]
      FROM [Tfs_%CollectionName%].[dbo].[LabObject]
      WHERE ObjectType = 'LabSystem'
      AND Name = '%MachineName%'
     
    With our names above:

    SELECT [LabObjectId], [Name], [Description],[ObjectType], [ParentId], [ContainerId], [PendingOperationId], [FailedOperationId], [InUseCount], [UsedId], [LabGuid], [CreationTime], [CreatedBy], [LastModifiedTime], [ModifiedBy], [LastAccessedTime]
      FROM [Tfs_MyCollection].[dbo].[LabObject]
      WHERE ObjectType = 'LabSystem'
      AND Name = 'AC-Web'
      -- Returns 62 for the LabObjectId, for example
    
    SELECT [LabObjectId], [Name], [Description],[ObjectType], [ParentId], [ContainerId], [PendingOperationId], [FailedOperationId], [InUseCount], [UsedId], [LabGuid], [CreationTime], [CreatedBy], [LastModifiedTime], [ModifiedBy], [LastAccessedTime]
      FROM [Tfs_MyCollection].[dbo].[LabObject]
      WHERE ObjectType = 'LabSystem'
      AND Name = 'AC-Services'
      -- Returns 63 for the LabObjectId, for example
    
    SELECT [LabObjectId], [Name], [Description],[ObjectType], [ParentId], [ContainerId], [PendingOperationId], [FailedOperationId], [InUseCount], [UsedId], [LabGuid], [CreationTime], [CreatedBy], [LastModifiedTime], [ModifiedBy], [LastAccessedTime]
      FROM [Tfs_MyCollection].[dbo].[LabObject]
      WHERE ObjectType = 'LabSystem'
      AND Name = 'AC-DB'
      -- Returns 64 for the LabObjectId, for example
     
    This will give you the final IDs you need to update. You'll need to run the following SQL script for each of the Lab Environment and Lab System IDs you have, filling in the Team Project Id as well.

    Update [Tfs_%CollectionName%].[dbo].[LabObject] set ContainerId = '%TeamProjectId%' where LabObjectId = %LabObjectId%

    With our values from above:

    -- For the Lab Environment
    Update [Tfs_MyCollection].[dbo].[LabObject] set ContainerId = 'D77640D4-1238-450F-A9E6-787130B12CB7' where LabObjectId = 61
    
    -- For the Lab Systems
    Update [Tfs_MyCollection].[dbo].[LabObject] set ContainerId = 'D77640D4-1238-450F-A9E6-787130B12CB7' where LabObjectId = 62
    Update [Tfs_MyCollection].[dbo].[LabObject] set ContainerId = 'D77640D4-1238-450F-A9E6-787130B12CB7' where LabObjectId = 63
    Update [Tfs_MyCollection].[dbo].[LabObject] set ContainerId = 'D77640D4-1238-450F-A9E6-787130B12CB7' where LabObjectId = 64

    I'm sure that someone much better at SQL than I could whip you up something that would do this all in one script.

    One final reminder. I do not recommend doing this unless absolutely necessary.
  • 11. září 2012 7:58
     
      Obsahuje kód

    Thanks a lot Jarrett,

    Using your approach, we have now been able to restructure our use of lab/TFS projects.

    I have made the following SQL script based on your SQL statements above. Note that I added a validation on source TFS project as well, as environments in different TFS projects can have same name. And if having multiple host groups, ensure that the host group is available to destination TFS project.

    And remember to change "rollback transaction" statement...

    /* 
     * Move Lab Environment to other TFS Project
     *
     * Based on script at:
     * http://social.msdn.microsoft.com/Forums/en-US/vslab/thread/38d82f55-baf4-42b5-b048-504bd5da30ab/
     *
     * Notes:
    * - Environment must be shut down before moving (otherwise it's not updated in TFS) * - If running with multiple host groups, ensure that host group is also available to destination TFS project */ begin transaction T1; declare @SourceTfsProjectName nvarchar(200); declare @SourceTfsProjectId uniqueidentifier; declare @DestinationTfsProjectName nvarchar(200); declare @DestinationTfsProjectId uniqueidentifier; declare @LabEnvironmentName nvarchar(200); declare @LabEnvironmentId bigint; set @LabEnvironmentName = 'LabEnvName'; set @SourceTfsProjectName = 'ProjectA'; set @DestinationTfsProjectName = 'ProjectB'; -- Get id of source and destination TFS projects select @SourceTfsProjectId = [ProjectId] from [dbo].[LabProject] where ProjectName = @SourceTfsProjectName select @DestinationTfsProjectId = [ProjectId] from [dbo].[LabProject] where ProjectName = @DestinationTfsProjectName -- Find id of lab environment (in source TFS project) select @LabEnvironmentId = [LabObjectId] from [dbo].[LabObject] where (ObjectType = 'LabEnvironment') and (Name = @LabEnvironmentName) and (ContainerId = @SourceTfsProjectId) -- Move lab environment to destination TFS project update [dbo].[LabObject] set ContainerId = @DestinationTfsProjectId where (LabObjectId = @LabEnvironmentId) and (ContainerId = @SourceTfsProjectId) -- Move all machines in environment update [dbo].[LabObject] set [dbo].[LabObject].ContainerId = @DestinationTfsProjectId where (ObjectType = 'LabSystem') and (ParentId = @LabEnvironmentId) and (ContainerId = @SourceTfsProjectId) rollback transaction T1;

    Best regards, Rasmus