def InitConfig(version, cluster_config, master_node_config, cfg_file=pathutils.CLUSTER_CONF_FILE): """Create the initial cluster configuration. It will contain the current node, which will also be the master node, and no instances. @type version: int @param version: configuration version @type cluster_config: L{objects.Cluster} @param cluster_config: cluster configuration @type master_node_config: L{objects.Node} @param master_node_config: master node configuration @type cfg_file: string @param cfg_file: configuration file path """ uuid_generator = config.TemporaryReservationManager() cluster_config.uuid = uuid_generator.Generate([], utils.NewUUID, _INITCONF_ECID) master_node_config.uuid = uuid_generator.Generate([], utils.NewUUID, _INITCONF_ECID) cluster_config.master_node = master_node_config.uuid nodes = { master_node_config.uuid: master_node_config, } default_nodegroup = objects.NodeGroup( uuid=uuid_generator.Generate([], utils.NewUUID, _INITCONF_ECID), name=constants.INITIAL_NODE_GROUP_NAME, members=[master_node_config.uuid], diskparams={}, ) nodegroups = { default_nodegroup.uuid: default_nodegroup, } now = time.time() maintenance = objects.Maintenance(serial_no=1, ctime=now, mtime=now) config_data = objects.ConfigData(version=version, cluster=cluster_config, nodegroups=nodegroups, nodes=nodes, instances={}, networks={}, disks={}, filters={}, maintenance=maintenance, serial_no=1, ctime=now, mtime=now) utils.WriteFile(cfg_file, data=serializer.Dump(config_data.ToDict()), mode=0600)
def __init__(self, cfg_file="/dev/null"): self._cur_group_id = 1 self._cur_node_id = 1 self._cur_inst_id = 1 self._cur_disk_id = 1 self._cur_os_id = 1 self._cur_nic_id = 1 self._cur_net_id = 1 self._default_os = None self._mocked_config_store = None self._temporary_macs = config.TemporaryReservationManager() self._temporary_secrets = config.TemporaryReservationManager() self._temporary_lvs = config.TemporaryReservationManager() self._temporary_ips = config.TemporaryReservationManager() super(ConfigMock, self).__init__(cfg_file=cfg_file, _getents=_StubGetEntResolver(), offline=True) with self.GetConfigManager(): self._CreateConfig()