Ejemplo n.º 1
0
def setup_datacenters(context):
    """Create datacenters for running vcenter samples"""
    # Find a Folder in which to put the Datacenters
    folder_summaries = folder_list_datacenter_folder(context)
    folder = folder_summaries[0].folder
    print("Creating datacenters in Folder '{}' ({})".format(
        folder, folder_summaries[0].name))

    # Create first datacenter
    datacenter1_name = context.testbed.config['DATACENTER1_NAME']
    datacenter1 = context.client.vcenter.Datacenter.create(
        Datacenter.CreateSpec(name=datacenter1_name, folder=folder))
    print("Created Datacenter '{}' ({})".format(datacenter1, datacenter1_name))

    # Create second datacenter
    datacenter2_name = context.testbed.config['DATACENTER2_NAME']
    datacenter2 = context.client.vcenter.Datacenter.create(
        Datacenter.CreateSpec(name=datacenter2_name, folder=folder))
    print("Created Datacenter '{}' ({})".format(datacenter2, datacenter2_name))

    # Save datacenter name to identifier mappings for later use
    context.testbed.entities['DATACENTER_IDS'] = {
        datacenter1_name: datacenter1,
        datacenter2_name: datacenter2
    }
    def ensure_state(self):
        dc_status = self.check_dc_state()
        if not dc_status:
            folder_summaries = self.dc_service.Folder.list(Folder.FilterSpec(type=Folder.Type.DATACENTER))
            folder = folder_summaries[0].folder

            datacenter1 = self.dc_service.Datacenter.create(
                Datacenter.CreateSpec(name=self.datacenter_name, folder=folder))
            self.module.exit_json(changed=True, datacenter_status="%s is created" % datacenter1)
        self.module.exit_json(changed=False, datacenter_status="%s already exists" % self.datacenter_name)